MyBB Community Forums

Full Version: Seperate Latest X Threads Page
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Im lookng to have a seperate page for the latest X amount of threads.
Ive seen many threads about adding similar things to sidebars, portals etc but nothing for a seperate page.

Ive got this code which I found on the forum but I need the page to follow the MyBB template, aswell as use pagination etc.

<?php
define("IN_MYBB", 1);
require_once("./global.php"); // Change this if needed
$tlimit = 5; // How many titles you want

$query = $db->query("SELECT * FROM ".TABLE_PREFIX."threads ORDER BY `tid` DESC LIMIT $tlimit");
while($fetch = $db->fetch_array($query)){
echo '<a href="./showthread.php?tid='.$fetch['tid'].'">'.$fetch['subject'].'</a><br />' . "\n";
}
?>

Anyone got any idea what needs to be done?

Thanks
Any idea how to add the mybb template though?
Using page manage, nothing happens.
Creating an independant page, nothing happens.
(2012-06-08, 01:28 PM)BleepyEvans Wrote: [ -> ]Im lookng to have a seperate page for the latest X amount of threads.
Ive seen many threads about adding similar things to sidebars, portals etc but nothing for a seperate page.

Ive got this code which I found on the forum but I need the page to follow the MyBB template, aswell as use pagination etc.

<?php
define("IN_MYBB", 1);
require_once("./global.php"); // Change this if needed
$tlimit = 5; // How many titles you want

$query = $db->query("SELECT * FROM ".TABLE_PREFIX."threads ORDER BY `tid` DESC LIMIT $tlimit");
while($fetch = $db->fetch_array($query)){
echo '<a href="./showthread.php?tid='.$fetch['tid'].'">'.$fetch['subject'].'</a><br />' . "\n";
}
?>

Anyone got any idea what needs to be done?

Thanks

Easiest way would be create two new global templates one which has the information for the header, the other that has the information for the footer.

Then use this:

http://community.mybb.com/thread-100986-...#pid736497

global customheader template:

<html>
<head>
<title>{$mybb->settings[bbname]}</title>
{$headerinclude}
</head>
<body>
{$header}
<br />

global customfooter template:

{$footer}
</body>
</html>

<?php
define("IN_MYBB", 1);
require_once ('./global.php');
eval("\$header1 = \"".$templates->get("customheader")."\";");
echo $header1;

required other content

eval("\$footer1 = \"".$templates->get("customfooter")."\";");
echo $footer1;
?>

And add all your content in between required content.
Which would look like this:

<?php
define("IN_MYBB", 1);
require_once ('./global.php');
$tlimit = 5; // How many titles you want

eval("\$header1 = \"".$templates->get("customheader")."\";");
echo $header1;

echo "<table width='100%' border='0'><thead><tr><th>Latest Threads</th></tr><tbody>";
$query = $db->query("SELECT * FROM ".TABLE_PREFIX."threads ORDER BY `tid` DESC LIMIT $tlimit");
while($fetch = $db->fetch_array($query)){
echo '<tr><td><a href="./showthread.php?tid='.$fetch['tid'].'">'.$fetch['subject'].'</a></td></tr>';
}
echo "</tbody></table>";

eval("\$footer1 = \"".$templates->get("customfooter")."\";");
echo $footer1;
?>

Think that would work for what you need.

Oh and change the layout like you wish with the table in these lines:

echo "<table width='100%' border='0'><thead><tr><th>Latest Threads</th></tr><tbody>";
$query = $db->query("SELECT * FROM ".TABLE_PREFIX."threads ORDER BY `tid` DESC LIMIT $tlimit");
while($fetch = $db->fetch_array($query)){
echo '<tr><td><a href="./showthread.php?tid='.$fetch['tid'].'">'.$fetch['subject'].'</a></td></tr>';
}
echo "</tbody></table>";

Also make sure your /global.php is ./global.php
I made a similar thing - recent posts. It pulls the data from the specified forums - like in the portal but a new page. It has two templates and one new php file.

You can see it here - if you are interested in the code I can post it.

http://www.leefish.nl/mybb/newposts.php
Thanks anori, exactly what I was after.

Leefish, is it possible to get the code to push the threads onto a new page please?

Thank you
here you go:

newposts.php
<?php
/**
 * MyBB 1.6
 * Copyright 2010 MyBB Group, All Rights Reserved
 *
 * Website: http://www.leefish.nl
 * License: Do not sell this 
 *
 * $Id: newposts.php 5297 2012-02-26 22:01:14Z Fish $
 */

define("IN_MYBB", 1);
//define("IN_newposts", 1);
define('THIS_SCRIPT', 'newposts.php');
// end editing

$change_dir = "./";

if(!@chdir($forumdir) && !empty($forumdir))
{
	if(@is_dir($forumdir))
	{
		$change_dir = $forumdir;
	}
	else
	{
		die("\$forumdir is invalid!");
	}
}

$templatelist = "newposts,newposts_latestthreads_thread_lastpost,newposts_latestthreads_thread,newposts_latestthreads,multipage_prevpage,multipage_nextpage,multipage_page_current,multipage_page,multipage_start,multipage_end";

require_once $change_dir."/global.php";
require_once MYBB_ROOT."inc/functions_post.php";
require_once MYBB_ROOT."inc/functions_user.php";
require_once MYBB_ROOT."inc/class_parser.php";
$parser = new postParser;

// Load global language phrases
$lang->load("portal");

// Fetch the current URL
$newposts_url = get_current_location();

add_breadcrumb("Recent Posts", $mybb->settings['bburl']."/newposts.php");
	
//pagination settings
$mybb->settings['newposts_showdiscussions'] = '1';
$mybb->settings['newposts_showpostsperpage'] = '10';
$newposts = 110 ;
$plugins->run_hooks("newposts_start");

// get forums user cannot view
$unviewable = get_unviewable_forums(true);
if($unviewable)
{
	$unviewwhere = " AND fid NOT IN ($unviewable)";
}

// Latest forum discussions
if($mybb->settings['newposts_showdiscussions'] == 1 && $mybb->settings['newposts_showpostsperpage'])

$page = intval($mybb->input['page']);
if($page < 1) $page = 1;
$perpage = intval($mybb->settings['newposts_showpostsperpage']);
$multipage = multipage($newposts, $perpage, $page, $_SERVER['PHP_SELF'].'?paged=1'.$brl);
{
	$altbg = alt_trow();
	$threadlist = '';
	$uv = str_replace('fid', 't.fid', $unviewwhere);

	$query = $db->query("
	SELECT t.*, u.username, u.displaygroup, u.avatar, u.usergroup, u.avatardimensions, f.name AS forumname, lp.avatar as lpavatar
		FROM ".TABLE_PREFIX."threads t
		LEFT JOIN ".TABLE_PREFIX."users u ON (u.uid=t.uid)
		LEFT JOIN ".TABLE_PREFIX."users lp ON (lp.uid=t.lastposteruid)
		LEFT JOIN ".TABLE_PREFIX."forums f ON (f.fid=t.fid)
		WHERE 1=1 $uv AND t.visible='1'
		AND t.fid NOT IN(15,20,43,44,68,45,36)
		ORDER BY t.lastpost DESC 
		LIMIT ".(($page-1)*$perpage).", ".$perpage
	);
	while($thread = $db->fetch_array($query))
	{
		$lastpostdate = my_date($mybb->settings['dateformat'], $thread['lastpost']);
		$lastposttime = my_date($mybb->settings['timeformat'], $thread['lastpost']);
		
		// Don't link to guest's profiles (they have no profile).
		
		if($thread['lastposteruid'] == 0)
		{
			$lastposterlink = $thread['lastposter'];
		}
		else
		{
		// Build the lastposter username
	       
			$lastposterlink = build_profile_link($thread['lastposter'], $thread['lastposteruid']);
		}
		if($thread['lpavatar'])
		{
		$thread['lpavatar'] = htmlspecialchars_uni($thread['lpavatar']);
		}
		else
		{
		$thread['lpavatar'] = $mybb->settings['bburl']."/images/avatars/guestfish.gif"; $thread['avatardimensions'] = "45|45"; 
		}
		if($thread['avatar'])
		{
		$thread['avatar'] = htmlspecialchars_uni($thread['avatar']);
		}
		else
		{
		$thread['avatar'] = $mybb->settings['bburl']."/images/avatars/guestfish.gif"; $thread['avatardimensions'] = "45|45"; 
		}
		if(my_strlen($thread['subject']) > 45)
		{
			$thread['subject'] = my_substr($thread['subject'], 0, 45) . "...";
		}
		// Build the author username
		$thread['username'] = format_name($thread['username'], $thread['usergroup'], $thread['displaygroup']);
		$threadstarter = build_profile_link($thread['username'], $thread['uid']);
		$thread['subject'] = htmlspecialchars_uni($parser->parse_badwords($thread['subject']));
		$thread['threadlink'] = get_thread_link($thread['tid']);
		$thread['lastpostlink'] = get_thread_link($thread['tid'], 0, "lastpost");
		$thread['forumname'] = htmlspecialchars_uni($parser->parse_badwords($thread['forumname']));
		eval("\$threadlist .= \"".$templates->get("newposts_latestthreads_thread")."\";");
		$altbg = alt_trow();
	}
	if($threadlist)
	{ 
		// Show the table only if there are threads
		eval("\$latestthreads = \"".$templates->get("newposts_latestthreads")."\";");
	}
}

$plugins->run_hooks("newposts_end");

eval("\$newposts = \"".$templates->get("newposts")."\";");
output_page($newposts);

?>

Templates (sorry, there are3, not 2)

Template name: newposts
<html>
<head>
<title>{$mybb->settings['bbname']}</title>
{$headerinclude}
</head>
<body>
{$header}
{$multipage}
{$latestthreads}
{$multipage}
{$footer}
</body>
</html>

and

Template name: newposts_latestthreads
<table border="0" cellspacing="{$theme['borderwidth']}" cellpadding="{$theme['tablespace']}" class="tborder" style="clear: both;">
	<tr>
		<td class="thead" colspan="3">
			<div>
				<strong>Recent Posts</strong>
			</div>
		</td>
	</tr>		
	<tr>
	<td class="tcat" align="left" width="80%"><strong>Subject/Author</strong></td>
	<td class="tcat" align="left" width="20%">
              <span class="smalltext"><strong>Last Posted</strong></span></td>
	</tr>
	{$threadlist}
</table>

and

Template name:newposts_latestthreads_thread
<tr>
<td class="{$altbg}"><div class="float_left" style="padding-right:8px;"><img src="{$thread['avatar']}" alt="" title="" width="45px" height="45px" /></div>
              <strong><a href="{$mybb->settings['bburl']}/{$thread['threadlink']}">{$thread['subject']}</a></strong><br />
 <span class="lastpost smalltext">{$threadstarter}</span>
</td>
              <td align="left" class="{$altbg}"><div class="float_left" style="padding-right:8px;"><img src="{$thread['lpavatar']}" alt="" title="" width="45px" height="45px" /></div>
	
		<div style="text-align:left;padding-right:8px;"><span class="lastpost smalltext">{$lastpostdate} {$lastposttime}<br />
		<a href="{$thread['lastpostlink']}">Last Post</a>: {$lastposterlink}</span></div>
	</td>
</tr>

You put the newposts.php in the forum root and the three templates in global templates. Please note that the guest avatar is hardcoded as I made this for my board, so you will need to point that to your own guest avatar image.

You find the code you need to change on lines 106 and 114 of the newposts.php. Please note, this file setup thing is free to use by anyone, but do not include this file and templates as part of a sold solution (theme plugin etc).
Wow, cheers thanks Big Grin
(2012-06-08, 02:46 PM)Leefish Wrote: [ -> ]here you go:

You put the newposts.php in the forum root and the three templates in global templates. Please note that the guest avatar is hardcoded as I made this for my board, so you will need to point that to your own guest avatar image.

You find the code you need to change on lines 106 and 114 of the newposts.php. Please note, this file setup thing is free to use by anyone, but do not include this file and templates as part of a sold solution (theme plugin etc).

How to replace {$threadstarter} with post's excerp?
And also how to add read/unread css class on it? For example unread post title style is bold, just like in the forum display?

Anyway thanks for this awesome trick! I used it on my forum. +Rep Smile