1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

HowTo: Add a dynamic footer to XenForo

Add title and links to the latest five resources and community threads to the bottom of XF

  1. LPH
    The footer on XenForo forum software may be modified to include the latest five resources to the resource manager and the latest five threads added to the community.

    This is the look of the final work.

    Tools:

    Text editor
    FTP software

    Screen Shot 2013-06-14 at 1.41.17 PM.png

    WARNING: Create this add-on locally first. Do not edit on a live site.

    Step 1: Create the file /library/TuxFooter/Listener/Footer.php

    Step 2: Add the following into the Footer.php file

    PHP:
    1.  
    2. <?php
    3.  
    4. class TuxFooter_Listener_Footer {
    5.  
    6.     public static function includeTuxFooter($hookName, &$contents, array $hookParams, XenForo_template_Abstract $template) {
    7.  
    8.         if($hookName == 'ad_below_bottom_breadcrumb') {
    9.  
    10.             ob_start();
    11.  
    12.             ?>
    13.             <div class="forum_footer">
    14.  
    15.             <div class="forum_posts_leftside">
    16.  
    17.             <h3>latest tux reports network resources</h3>
    18.  
    19.             <?php
    20.  
    21.  
    22.  
    23.             /* Script to pull the latest updated resources from the XF Resource Manager */
    24.  
    25.             /** @var $resModel  XenResource_Model_Resource */
    26.             $resModel = XenForo_Model::create('XenResource_Model_Resource');
    27.             $fetchOptions = array('limit' => 5, 'order' => 'resource_date', 'direction' => 'desc');
    28.  
    29.             $rmupdates = $resModel->getResources(array(), $fetchOptions);
    30.  
    31.             foreach ($rmupdates AS $rmupdate) {
    32.                 echo ("<div class='entry-meta'><a href='http://community.tuxreportsnetwork.com/" . XenForo_Link::buildPublicLink('resources', $rmupdate) . "' >" . XenForo_Helper_String::wholeWordTrim($rmupdate['title'], 55) . "</a> <br /></div>"); // Echo the title with a link.
    33.             }
    34.  
    35.  
    36.  
    37.             ?>
    38.  
    39.                     </div><!-- Close forum_posts_leftside -->
    40.  
    41.                     <div class="forum_posts">
    42.  
    43.                         <h3>latest posts from our community</h3>
    44.  
    45.                         <?php
    46.  
    47.                         /* Script to pull the latest posts from the XF Forum */
    48.  
    49.                         $db = XenForo_Application::getDb();
    50.  
    51.                         if ( !$db ) {
    52.  
    53.                             die( 'This script did not connect to the database' . mysql_error() );
    54.                         }
    55.  
    56.                         $thread_qry = "
    57.                                    SELECT * FROM `xf_thread`
    58.                                    ORDER BY `last_post_date` DESC
    59.                                    LIMIT 5
    60.                                    ";
    61.  
    62.                         $threads = XenForo_Application::get('db')->fetchAll($thread_qry);
    63.  
    64.                         foreach (    $threads AS $thread ) {
    65.  
    66.                             echo ("<div class='entry-meta'><a href='http://community.tuxreportsnetwork.com/" . XenForo_Link::buildPublicLink('threads', $thread) . "' >" . XenForo_Helper_String::wholeWordTrim($thread['title'], 48) . "</a> <span style='float:right; margin-right:60px'>Viewed: " . $thread['view_count']
    67.                                     . "</span><br /></div>"); // Echo the title with a link.
    68.  
    69.                         }
    70.  
    71.                         ?>
    72.  
    73.                     </div><!-- Close forum_posts -->
    74.  
    75.                 </div><!-- Forum Footer -->
    76. <?php
    77.                 $contents .= ob_get_contents();
    78.                 ob_end_clean();
    79.             }
    80.  
    81.     }
    82.  
    83. }
    84. ?>
    Adjust the links for the links so that they match your website.

    Step 3: Enable development for your community

    Edit the /library/config.php
    Add the line
    PHP:
    1. $config['debug'] = true;
    Save the file

    Step 4: Log into your community's admin panel.

    Step 5: Create the add-n

    development > Create Add-on

    Screen Shot 2013-06-14 at 1.49.32 PM.png

    Step 6: Create the listener

    Add the information as shown in the image. Save Event Listener.

    Screen Shot 2013-06-14 at 1.52.13 PM.png

    Step 7: Test the loading of your site. Did the footer now show?

    Step 8: Add the CSS information to your liking.

    Step 9: Comment out the debug information in the /library/config.php file.

    If you are able to do this work locally then complete the same steps on your live site.
    Pokschubin likes this.