Search the Community
Showing results for tags 'latest posts'.
-
*** 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