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.
Announcement
Collapse
No announcement yet.
How to Display Last X Posts on Home Page
Collapse
X
-
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. -
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
-
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.comComment
-
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
-
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>";
}
}
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
-
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
-
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
widgetinstance 262 (Related Topics) skipped due to lack of content & hide_module_if_empty option.
Comment