Jump to content

Recent Posts w/o Plugin
   (2 reviews)

c.widow
  • This guide offers two options to installing and running recent posts on your forum. It also uses the recent posts from the portal so portal settings will dictate how this will work but I have updated this to include thread prefixes and username/group display to properly show.

     

    Version 1.8.x

    Software: MyBB

*** Notice:  This topic has a section for users wishing to use the PHP In Templates / Complex Templates plugin or a section for users who are okay with editing their core files. I would personally suggest using the plugin that allows PHP in templates as that way you do not have to touch core files however it is up to you! PHP In Templates / Complex Templates also has MANY other useful features especially when in regards to adding custom scripts to your site without having to add them to core files.

 

Recent Posts w/o Plugin

Tutorial Created By: isoldehn
Tutorial Permissions: Please do not re-post this tutorial else where, instead link someone to this thread.
Tutorial Needs: Overall, the ability to copy and paste.
- Knowledge Of MyBB Templates 
- FTP Access & Knowledge On Editing Core Files OR Ability To Upload Plugin

 

Using PHP In Templates / Complex Templates Plugin

or

Altering Core Files

 

USING PHP In Templates / Complex Templates Plugin

You will need to first install the plugin and activate it. I know that this plugin needs to be extracted and if you do not have the time or resources to do such I have attached a file already extracted for you.

 

Once the plugin is installed and activated you will need to figure out where you wish for this to show, for my example I will be doing this on the index page in a side bar. Open Templates & Style --> Templates --> your current set --> Index Page Templates --> index.

 

Lets start with the simple additions and modifying the index to have a sidebar and include the $lattestthreads box.

FIND:

{$forums}

REPLACE WITH:

	<div style="width: 70%; padding-right: 5px; box-sizing: border-box; float: left; display: inline-block;">
		{$forums}
	</div>
	<div style="width: 30%; padding-left: 5px; box-sizing: border-box; float: right; display: inline-block;">
		{$latestthreads}
	</div>

 

Now lets include our PHP code right above {$latestthreads}!

<?php
$latestthreads = '';
// Latest forum discussions
if($mybb->settings['portal_showdiscussions'] != 0 && $mybb->settings['portal_showdiscussionsnum'] && $mybb->settings['portal_excludediscussion'] != -1)
{
	$altbg = alt_trow();
	$threadlist = '';

	$excludeforums = '';
	if(!empty($mybb->settings['portal_excludediscussion']))
	{
		$excludeforums = "AND t.fid NOT IN ({$mybb->settings['portal_excludediscussion']})";
	}

	$query = $db->query("
		SELECT t.tid, t.fid, t.uid, t.lastpost, t.lastposteruid, t.lastposter, t.subject, t.replies, t.views, t.prefix, u.username, u.usergroup, u.displaygroup
		FROM ".TABLE_PREFIX."threads t
		LEFT JOIN ".TABLE_PREFIX."users u ON (u.uid=t.uid)
		WHERE 1=1 {$excludeforums}{$tunviewwhere} AND t.visible='1' AND t.closed NOT LIKE 'moved|%'
		ORDER BY t.lastpost DESC
		LIMIT 0, ".$mybb->settings['portal_showdiscussionsnum']
	);
	while($thread = $db->fetch_array($query))
	{
		$forumpermissions[$thread['fid']] = forum_permissions($thread['fid']);

		// Make sure we can view this thread
		if(isset($forumpermissions[$thread['fid']]['canonlyviewownthreads']) && $forumpermissions[$thread['fid']]['canonlyviewownthreads'] == 1 && $thread['uid'] != $mybb->user['uid'])
		{
			continue;
		}

		$lastpostdate = my_date('relative', $thread['lastpost']);
		if(!$thread['lastposteruid'] && !$thread['lastposter'])
		{
			$lastposter = htmlspecialchars_uni($lang->guest);
		}
		else
		{
			$lastposter = htmlspecialchars_uni($thread['lastposter']);
		}
		$thread['replies'] = my_number_format($thread['replies']);
		$thread['views'] = my_number_format($thread['views']);

		// Don't link to guest's profiles (they have no profile).
		if($thread['lastposteruid'] == 0)
		{
			$lastposterlink = $lastposter;
		}
		else
		{
			$lastposterlink = build_profile_link(format_name($thread['lastposter'], $thread['usergroup'], $thread['displaygroup']), $thread['lastposteruid']);
		}

		$thread['subject'] = $thread['fullsubject'] = $parser->parse_badwords($thread['subject']);
		if(my_strlen($thread['subject']) > 25)
		{
			$thread['subject'] = my_substr($thread['subject'], 0, 25) . "...";
		}
		$prefix = build_prefixes($thread['prefix']);
		$prefix = $prefix['displaystyle'];
		$thread['subject'] = $prefix . " " . htmlspecialchars_uni($thread['subject']);
		$thread['fullsubject'] = $prefix . " " . htmlspecialchars_uni($thread['fullsubject']);
		$thread['threadlink'] = get_thread_link($thread['tid']);
		$thread['lastpostlink'] = get_thread_link($thread['tid'], 0, "lastpost");
		$thread['forumlink'] = get_forum_link($thread['fid']);
		$thread['forumname'] = $forum_cache[$thread['fid']]['name'];
		eval("\$threadlist .= \"".$templates->get("portal_latestthreads_thread")."\";");
		$altbg = alt_trow();
	}
	if($threadlist)
	{
		// Show the table only if there are threads
		eval("\$latestthreads = \"".$templates->get("portal_latestthreads")."\";");
	}
}
?>

 

To further stylize your $latestthreads template navigate to Portal Templates --> portal_latestthreads & portal_latestthreads_thread.

 

You are finished!

 

ALTERING Core Files

You will need to navigate to you File Manager area (either through cPanel or an FTP client of some sorts).

 

I will be using the index page for this tutorial so you should open index.php IN A CODE EDITOR SOFTWARE, other editors like Notepad may cause issues. Find $plugins->run_hooks('index_start'); this is where we will begin adding our script!

 

Right below the line I had you find above add the following:

$latestthreads = '';
// Latest forum discussions
if($mybb->settings['portal_showdiscussions'] != 0 && $mybb->settings['portal_showdiscussionsnum'] && $mybb->settings['portal_excludediscussion'] != -1)
{
	$altbg = alt_trow();
	$threadlist = '';

	$excludeforums = '';
	if(!empty($mybb->settings['portal_excludediscussion']))
	{
		$excludeforums = "AND t.fid NOT IN ({$mybb->settings['portal_excludediscussion']})";
	}

	$query = $db->query("
		SELECT t.tid, t.fid, t.uid, t.lastpost, t.lastposteruid, t.lastposter, t.subject, t.replies, t.views, t.prefix, u.username, u.usergroup, u.displaygroup
		FROM ".TABLE_PREFIX."threads t
		LEFT JOIN ".TABLE_PREFIX."users u ON (u.uid=t.uid)
		WHERE 1=1 {$excludeforums}{$tunviewwhere} AND t.visible='1' AND t.closed NOT LIKE 'moved|%'
		ORDER BY t.lastpost DESC
		LIMIT 0, ".$mybb->settings['portal_showdiscussionsnum']
	);
	while($thread = $db->fetch_array($query))
	{
		$forumpermissions[$thread['fid']] = forum_permissions($thread['fid']);

		// Make sure we can view this thread
		if(isset($forumpermissions[$thread['fid']]['canonlyviewownthreads']) && $forumpermissions[$thread['fid']]['canonlyviewownthreads'] == 1 && $thread['uid'] != $mybb->user['uid'])
		{
			continue;
		}

		$lastpostdate = my_date('relative', $thread['lastpost']);
		if(!$thread['lastposteruid'] && !$thread['lastposter'])
		{
			$lastposter = htmlspecialchars_uni($lang->guest);
		}
		else
		{
			$lastposter = htmlspecialchars_uni($thread['lastposter']);
		}
		$thread['replies'] = my_number_format($thread['replies']);
		$thread['views'] = my_number_format($thread['views']);

		// Don't link to guest's profiles (they have no profile).
		if($thread['lastposteruid'] == 0)
		{
			$lastposterlink = $lastposter;
		}
		else
		{
			$lastposterlink = build_profile_link(format_name($thread['lastposter'], $thread['usergroup'], $thread['displaygroup']), $thread['lastposteruid']);
		}

		$thread['subject'] = $thread['fullsubject'] = $parser->parse_badwords($thread['subject']);
		if(my_strlen($thread['subject']) > 25)
		{
			$thread['subject'] = my_substr($thread['subject'], 0, 25) . "...";
		}
		$prefix = build_prefixes($thread['prefix']);
		$prefix = $prefix['displaystyle'];
		$thread['subject'] = $prefix . " " . htmlspecialchars_uni($thread['subject']);
		$thread['fullsubject'] = $prefix . " " . htmlspecialchars_uni($thread['fullsubject']);
		$thread['threadlink'] = get_thread_link($thread['tid']);
		$thread['lastpostlink'] = get_thread_link($thread['tid'], 0, "lastpost");
		$thread['forumlink'] = get_forum_link($thread['fid']);
		$thread['forumname'] = $forum_cache[$thread['fid']]['name'];
		eval("\$threadlist .= \"".$templates->get("portal_latestthreads_thread")."\";");
		$altbg = alt_trow();
	}
	if($threadlist)
	{
		// Show the table only if there are threads
		eval("\$latestthreads = \"".$templates->get("portal_latestthreads")."\";");
	}
}

 

Open Templates & Style --> Templates --> your current set --> Index Page Templates --> index.

 

Lets start with the simple additions and modifying the index to have a sidebar and include the $lattestthreads box.

FIND:

{$forums}

REPLACE WITH:

	<div style="width: 70%; padding-right: 5px; box-sizing: border-box; float: left; display: inline-block;">
		{$forums}
	</div>
	<div style="width: 30%; padding-left: 5px; box-sizing: border-box; float: right; display: inline-block;">
		{$latestthreads}
	</div>

To further stylize your $latestthreads template navigate to Portal Templates --> portal_latestthreads & portal_latestthreads_thread.

 

You are finished!

phptpl.php

Edited by isoldehn





User Feedback

Create an account or sign in to leave a review

You need to be a member in order to leave a review

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

gelly

   1 of 1 member found this review helpful 1 / 1 member

Thank you for this tutorial! Very easy and 10000% less headaches than dealing with Prostats or other plugins out there.

  • Fuck Yeah! 1

Share this review


Link to review
Kit the Human

  

This is my absolute most favourite tip for mybb. Screw adding prostats with it's billion features you won't use and it's tables within tables within tables structure...just do this. It's simpler and much cleaner. I'm so glad that you shared it here!

Response from the author:

I am personally NOT a fan of ProStats for every reason that you mentioned. I have also seen issues with ProStats dates turning to all 0's from time to time. Using the portals latestthreads is a better option for sure! ❤️

Share this review


Link to review

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use, Guidelines and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.