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

Dynamic Content in Template Footer

LPH

Well-known member
#1
I realize XF 1.2 may change the answer to this question, so maybe I should just wait on this project until 1.2 is available... but ...

I want the last 5 threads and last 5 resources to show in the XF footer - just as it does on the WordPress side.

Since this is dynamic content generated by XF, is there a way to get this information into the footer template without doing a callback to a php page?

Or

Should I move the code in the footer.php of the WordPress into its own php file and place it within XenForo library directory then do a callback?
 

LPH

Well-known member
#2
After watching several videos and doing a bit more reading, this thread sort of brings to light how to build a static footer. My interest is a dynamic footer; that is, pulling the latest threads and resources.
Please look these steps over and let me know if this is the right track....

Step 1: create /library/TuxFooter/Listener/Footer.php

PHP:
<?php

class TuxFooter_Listener_Footer {

   public static function includeTuxFooter($hookName, &$contents, array $hookParams, XenForo_template_Abstract $template) {

     if($hookName == 'footer') {

       ob_start();

       ?>
       <div class="forum_footer">

       <div class="forum_posts_leftside">

       <h3>The latest tablet resources</h3>

       <?php



       /* Script to pull the latest updated resources from the XF Resource Manager */

       /** @var $resModel  XenResource_Model_Resource */
       $resModel = XenForo_Model::create('XenResource_Model_Resource');
       $fetchOptions = array('limit' => 5, 'order' => 'resource_date', 'direction' => 'desc');

       $rmupdates = $resModel->getResources(array(), $fetchOptions);

       foreach ($rmupdates AS $rmupdate) {
         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.
       }



       ?>

           </div><!-- Close forum_posts_leftside -->

           <div class="forum_posts">

             <h3>The following posts are from our community</h3>

             <?php

             /* Script to pull the latest posts from the XF Forum */

             $db = XenForo_Application::getDb();

             if ( !$db ) {

               die( 'This script did not connect to the database' . mysql_error() );
             }

             $thread_qry = "
                   SELECT * FROM `xf_thread`
                ORDER BY `last_post_date` DESC
                LIMIT 5
                   ";

             $threads = XenForo_Application::get('db')->fetchAll($thread_qry);

             foreach (   $threads AS $thread ) {

               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']
                   . "</span><br /></div>"); // Echo the title with a link.

             }

             ?>

           </div><!-- Close forum_posts -->

         </div><!-- Forum Footer -->
<?php
         $contents .= ob_get_contents();
         ob_end_clean();
       }

   }

}
?>

Step 2. Enable development mode
Step 3. Go into admin->create add-on
Step 4. Create Listener

Is this the right track? Is this the best way to get a dynamic footer? Is there an easier way? Sorry - I couldn't figure out how to do dynamic in the footer template - is that possible?
 
Last edited:

LPH

Well-known member
#4
OK. It isn't quite right. The footer is ending up below some things. Is there s a different hook?

Dynamic_TxuFooter.PNG

Update: In case someone trips over this thread, the template hook to use is not footer but ad_below_bottom_breadcrumb. This works out much nicer.
 
Last edited: