Announcement

Collapse
No announcement yet.

How to Display Last X Posts on Home Page

Collapse
X
 
  • Time
  • Show
Clear All
new posts

  • How to Display Last X Posts on Home Page

    I would like to display links to the last X posts in the "Whats Going On" area of my forums' home page. Can someone please explain how to do this? Thanks.

  • #2
    Without source code modification you could do this with JS through external.php

    More information about the External Data Provider can be found in the online manual.

    Comment


    • #3
      You can use the same method I posted in this thread. Just remove the WHERE forumid=1 code from the PHP code I posted, like this:

      PHP Code:
      if (THIS_SCRIPT == 'index'

          
      $threads $DB_site->query("SELECT threadid, title 
                  FROM " 
      TABLE_PREFIX "thread 
                  ORDER BY threadid 
                  DESC 
                  LIMIT 6"
      ); 

          while (
      $thread $DB_site->fetch_array($threads)) 
          { 
              
      $threadbits .= "<a href=\"showthread.php?" $session[sessionurl] . "t=" $thread[threadid] . "\">" $thread[title] . "</a><br />"
          } 

      Comment


      • #4
        That is quite cool Jake Thank you for sharing.

        Comment


        • #5
          Thanks for that Jake, I'll take a look at it in detail (I'm not - yet - experienced with hacking vB).

          What I'm looking to achieve is the same as that used by Wilders in their forum home page here: http://www.wilderssecurity.com

          Comment


          • #6
            That site is showing the forum names, author names, and post dates. The PHP code to pull that information is a little more involved. I will see what I can do...

            Comment


            • #7
              There is an add-on on vbulletin.org at this page. It was written for vB 2 but it works okay on vB 3 at my site. It will show the last xx posts on a non-vb page.
              Harold Kost

              Comment


              • #8
                Here you go. This matches that site exactly.

                Go to your:

                Admin CP -> Styles & Templates -> Style Manager -> « » -> PHP Include Code Templates » -> phpinclude_start

                Add this code to that template:

                PHP Code:
                if (THIS_SCRIPT == 'index')
                {
                    
                $posts $DB_site->query("SELECT " TABLE_PREFIX "post.postid, " TABLE_PREFIX "post.dateline, " TABLE_PREFIX "thread.title AS threadtitle, " TABLE_PREFIX "forum.forumid, " TABLE_PREFIX "forum.title AS forumtitle, " TABLE_PREFIX "user.username, " TABLE_PREFIX "user.userid
                            FROM " 
                TABLE_PREFIX "post
                            LEFT JOIN " 
                TABLE_PREFIX "user ON (" TABLE_PREFIX "user.userid = " TABLE_PREFIX "post.userid)
                            LEFT JOIN " 
                TABLE_PREFIX "thread ON (" TABLE_PREFIX "thread.threadid = " TABLE_PREFIX "post.threadid)
                            LEFT JOIN " 
                TABLE_PREFIX "forum ON (" TABLE_PREFIX "forum.forumid = " TABLE_PREFIX "thread.forumid)
                            ORDER BY " 
                TABLE_PREFIX "post.postid
                            DESC
                            LIMIT 10"
                );

                    while (
                $post $DB_site->fetch_array($posts))
                    {
                        
                $postbits .= "<tr><td class=\"smallfont\" align=\"right\">[<a href=\"forumdisplay.php?" $session[sessionurl] . "f=" $post[forumid] . "\">" $post[forumtitle] . "</a>]</td><td width=\"10\"></td><td class=\"smallfont\" align=\"left\"><a href=\"showthread.php?" $session[sessionurl] . "p=" $post[postid] . "\">" $post[threadtitle] . "</a> by <a href=\"member.php?" $session[sessionurl] . "u=" $post[userid] . "\">" $post[username] . "</a> on " vbdate('l'$post[dateline]) . " at " vbdate('g:i A'$post[dateline]) . "</td></tr>";
                    }

                Then go to your:

                Admin CP -> Styles & Templates -> Style Manager -> « » -> Forum Home Templates » -> FORUMHOME

                Find this code and add the red code:

                Code:
                <!-- what's going on box -->
                <table class="tborder" cellpadding="$stylevar[cellpadding]" cellspacing="$stylevar[cellspacing]" border="0" width="100%" align="center">
                <thead>
                	<tr>
                		<td class="tcat" colspan="2">$vbphrase[whats_going_on]</td>
                	</tr>
                </thead>
                
                [color=red]<!-- latest posts -->
                <tbody>
                	<tr>
                		<td class="thead" colspan="2">
                			<a style="float:$stylevar[right]" href="#top" onclick="return toggle_collapse('forumhome_latestposts')"><img id="collapseimg_forumhome_latestposts" src="$stylevar[imgdir_button]/collapse_thead$vbcollapse[collapseimg_forumhome_latestposts].gif" alt="" border="0" /></a>
                			The 10 last posts on the forum
                		</td>
                	</tr>
                </tbody>
                <tbody id="collapseobj_forumhome_latestposts" style="$vbcollapse[collapseobj_forumhome_latestposts]">
                	<tr>
                		<td class="alt2"><a href="online.php?$session[sessionurl]"><img src="$stylevar[imgdir_statusicon]/forum_new.gif" alt="Search for latest posts" border="0" /></a></td>
                		<td class="alt1" width="100%">
                			<div class="smallfont">
                				<div style="white-space: nowrap">
                
                <table border="0" cellspacing="0" cellpadding="0">
                
                $postbits
                
                </table>
                
                				</div>
                			</div>
                		</td>
                	</tr>
                </tbody>
                <!-- end latest posts -->[/color]
                
                <if condition="$show['loggedinusers']">
                <!-- logged-in users -->
                <tbody>
                	<tr>

                Comment


                • #9
                  Thanks, Jake, for such a quick and helpful response. I have followed your instructions closely to update the two templates you describe, but find nothing added to the "What's Going On" section.

                  Might there be a simple something else I should also be doing?

                  Comment


                  • #10
                    I tested this code and it worked fine. Maybe you entered the code incorrectly.

                    Double check my instructions. Make sure you are viewing the same style whose templates you are editing. If it still doesn't work then you can send me a private message with a URL and admin login for your forums and I will take a look.

                    Comment


                    • #11
                      Just to confirm that Jake cleared this up for me by PM - I had made a crock of it after all. Thanks, Jake for all your help.

                      Comment

                      widgetinstance 262 (Related Topics) skipped due to lack of content & hide_module_if_empty option.
                      Working...
                      X
                      😀
                      🥰
                      🤢
                      😎
                      😡
                      👍
                      👎