We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 21671
    • 244 Posts
    Hi All!

    I recently developed a website called Nantucket Triathlon club in evo 1.05 that had an Simple Machines Forum (smf) linked to the site. The forum sat in its on folder on the server. The folder was located in the root of the website and was named "forums."

    The users of the forum were NOT linked as web users for modx. I struggled with the implementation and thought I’d share my experiences to help other Newbies work through the process. Thus this short tutorial. This is not going to teach you how to automatically bridge the forum users with your modx site, but it will show you how to do a simple implementation that has a "most recent forum posts" content block on the homepage.

    You should check out the finished product at www.nantuckettriathlonclub.org and the forum homepage is at http://www.nantuckettriathlonclub.org/forums/index.php.

    If you spend any time in our MODX forum, my forum template should look familiar!

    On the homepage of the website, take note of the latest forum posts down on the right hand side of the page. If you click on a post’s link it will take you into the forum to the appropriate post.

    None of this is rocket science in practice, so let me show you how to do it.

    1. I included a snippet like so in the homepage template:

    The snippet is called uncached so that it pulls the most recent topics!

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    [!smfInclude!]
    


    with the snippet’s code is super simple:
    <?php
    require("forums/SSI.php");
    ?>
    


    The require has to point to the location of the SSI.php file which is SMF’s builtin file to integrate the forum in your website. You can learn more about SSI at http://docs.simplemachines.org/index.php?topic=400.0 and see code examples at http://www.simplemachines.org/community/ssi_examples.php

    The most recent posts are is a snippet:
    [!SMFssi!]
    


    with the snippet’s code:
    <?php
    $posts = ssi_recentTopics(8, null, 'array'); //shows the 8 most topics, which are each and every post. both newtopics and replies
    
    	echo '<ul class="ssi_ul">';
    
    foreach ($posts as $post) {
         $post['board']['link'] = str_replace($scripturl, SITEURL.'forums/', $post['board']['link']); //'forums/ points to folder inside the root folder that the forums live inside.
         $post['board']['href'] = str_replace($scripturl, SITEURL.'forums/', $post['board']['href']);  //
         $post['poster']['link'] = str_replace($scripturl, SITEURL.'forums/', $post['poster']['link']);
         $post['poster']['href'] = str_replace($scripturl, SITEURL.'forums/', $post['poster']['href']); 
         $post['link'] = str_replace($scripturl, SITEURL.'forums/', $post['link']);
         $post['href'] = str_replace($scripturl, SITEURL.'forums/', $post['href']);
         echo '<li>', $post['new'] ? '' : '<li><a href="' . $scripturl . '?topic=' . $post['topic'] . '.msg' . $post['new_from'] . ';topicseen#new"><img src="' . $settings['images_url'] . '/' . $context['user']['language'] . '/new.gif" alt="' . $txt[302] . '" border="0" /></a>';
         echo' <a href="', $post['href'],'"><strong>', $post['subject'],'</strong></a>  <br /> by ' ,  $post['poster']['link'],' (',$post['board']['link'],')<span class="forumDate">',date("m/d/y h:m a", $post['timestamp']),'</span></li>';}
         echo'</ul>';
    ?>
    
    


    You’ll notice the
    $post['board']['link'] = str_replace($scripturl, SITEURL.'forums/', $post['board']['link']); 

    points to the folder that the forums actually live inside. I’ve also commented the code a bit to explain what’s going on.

    I hope this super rudimentary tutorial helps someone figure out how to get a forum going with MODX. There is a ton of room to improve on my solution including bridging the users between MODX and SMF. It looked like the bridge was very difficult to implement with newer versions of MODX evolution. If anyone has done this and wants to add on posts below, that would be super cool. Keep in mind that I’m not a php guru and this was hacked together, so I might not be able to answer every question.

    Best of luck,

    -Noah
      • 26931
      • 2,314 Posts
      Hi Noah, thanks for sharing! smiley
        • 21671
        • 244 Posts
        HI Sharkbait,

        My pleasure. Again I know it isn’t super detailed, but I hope it is helpful.

        -Noah