MyBB Community Forums

Full Version: Help pulling recent topics from ONLY ONE forum...
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Greetings-

I am using the following plugin Recent Topics On Index Page

My URL is Sellmyaudio.net

I would like to only pull the recent topics from one forum, by forum ID and present it in that box... can someone help me out?

Lets assume the forum I want to pull topics from is "1"

Here is the code from the plugin;
$plugins->add_hook("index_end", "recenttopicsindex_show");

function recenttopicsindex_info()
{

	return array(
		"name"		=> "Recent Topics Index Page",
		"description"		=> "Adds Recent Topics to the index page",
		"website"		=> "http://www.mybbhacks.com",
		"author"		=> "vbgamer45",
		"authorsite"		=> "http://www.mybbhacks.com",
		"version"		=> "1.0.2",
		"guid" 			=> "3244972b3e44b82b52b12594a6af9261",
		"compatibility"	=> "1*"
		);
}


function recenttopicsindex_install()
{
	global $mybb, $db;
	// Create Tables/Settings
	$db->query("INSERT  INTO ".TABLE_PREFIX."settings (sid, name, title, description, optionscode, value, disporder, gid) VALUES (NULL, 'recenttopicslimit', 'Recent Topics To Show', 'The number of recent topics you wish to display on the main index page', 'text', '10', 1, 6);");

	rebuild_settings();


}

function recenttopicsindex_is_installed()
{
	global $db;
	$query = $db->write_query("SELECT * FROM " . TABLE_PREFIX . "settings WHERE `name` = 'recenttopicslimit'");

	if($db->num_rows($query) > 0)
		return true;
	else
		return false;
}

function recenttopicsindex_uninstall()
{
	global $mybb, $db;

	$db->query("DELETE FROM ".TABLE_PREFIX."settings WHERE name = 'recenttopicslimit'");

	rebuild_settings();
}


function recenttopicsindex_activate()
{
  require_once MYBB_ROOT."/inc/adminfunctions_templates.php";

  $returnStatus1 = find_replace_templatesets("index", "#".preg_quote('{$forums}') . "#i", '{$forums}' . "\n" . '{$recenttopics}');


}

function recenttopicsindex_deactivate()
{
  require_once MYBB_ROOT."/inc/adminfunctions_templates.php";

  $returnStatus1 = find_replace_templatesets(
  "index", "#".preg_quote('{$forums}' . "\n" . '{$recenttopics}') . "#i",
  '{$forums}',0);


}

function recenttopicsindex_show()
{
	global $db, $mybb, $page, $recenttopics, $theme, $lang, $permissioncache;

	$lang->load('recenttopicsindex');

	require_once MYBB_ROOT."inc/functions_search.php";

	if (empty($mybb->settings['recenttopicslimit']))
		$mybb->settings['recenttopicslimit'] = 10;

	$recenttopics .= '<table border="0" cellspacing="' . $theme['borderwidth'] . '" cellpadding="' . $theme['tablespace'] . '" class="tborder">
<thead>
<tr>
<td class="thead" colspan="2">

<div><strong>' . $lang->recenttopics . '</strong></div>
</td>
</tr>
</thead>';

	// Run the Query
	
    // !!! FIX private forum exposure!!!
   if ( !is_array($permissioncache) ||(is_array($permissioncache) && ((count($permissioncache)==1) && (isset($permissioncache['-1']) && ($permissioncache['-1'] = "1"))))) 
       $permissioncache = forum_permissions();

	$unsearchforums = get_unsearchable_forums();
	if($unsearchforums)
		$where_sql .= " AND t.fid NOT IN ($unsearchforums)";

	$inactiveforums = get_inactive_forums();
	if ($inactiveforums)
		$where_sql .= " AND t.fid NOT IN ($inactiveforums)";


	$query = $db->query("
	SELECT
		t.tid, t.fid, t.subject, t.lastposteruid, t.lastposter, t.lastpost, f.name
	FROM ".TABLE_PREFIX."threads as t,  ".TABLE_PREFIX."forums as f
	WHERE f.fid = t.fid AND t.visible = 1 $where_sql
	ORDER BY t.lastpost DESC LIMIT " . $mybb->settings['recenttopicslimit']);
	while($threadRow = $db->fetch_array($query))
	{
		$recenttopics .= '<tr>';
		$subject = my_substr($threadRow['subject'], 0, 50);
		$subject = htmlspecialchars_uni($subject);
		$postdate = my_date($mybb->settings['dateformat'], $threadRow['lastpost']);
		$posttime = my_date($mybb->settings['timeformat'], $threadRow['lastpost']);

		$recenttopics .= '<td class="trow1">
		<a href="showthread.php?tid=' . $threadRow['tid'] . '&action=lastpost">' . $subject .'</a> '  . $lang->recenttopics_by . (!empty($threadRow['lastposteruid']) ? ' <a href="member.php?action=profile&uid=' . $threadRow['lastposteruid'] . '">' . $threadRow['lastposter'] . '</a>' : $threadRow['lastposter']) . ' (<a href="forumdisplay.php?fid=' . $threadRow['fid'] . '">' . $threadRow['name'] . '</a>)
		</td>
		<td class="trow1">' .
		$postdate . ' ' . $posttime . '
		</td>
		</tr>';
	}


	$recenttopics .= "</table><br />";



}


?>

Any suggestions?
Try this code;

$plugins->add_hook("index_end", "recenttopicsindex_show");

function recenttopicsindex_info()
{

    return array(
        "name"        => "Recent Topics Index Page",
        "description"        => "Adds Recent Topics to the index page",
        "website"        => "http://www.mybbhacks.com",
        "author"        => "vbgamer45",
        "authorsite"        => "http://www.mybbhacks.com",
        "version"        => "1.0.2",
        "guid"             => "3244972b3e44b82b52b12594a6af9261",
        "compatibility"    => "1*"
        );
}


function recenttopicsindex_install()
{
    global $mybb, $db;
    // Create Tables/Settings
    $db->query("INSERT  INTO ".TABLE_PREFIX."settings (sid, name, title, description, optionscode, value, disporder, gid) VALUES (NULL, 'recenttopicslimit', 'Recent Topics To Show', 'The number of recent topics you wish to display on the main index page', 'text', '10', 1, 6);");

    rebuild_settings();


}

function recenttopicsindex_is_installed()
{
    global $db;
    $query = $db->write_query("SELECT * FROM " . TABLE_PREFIX . "settings WHERE `name` = 'recenttopicslimit'");

    if($db->num_rows($query) > 0)
        return true;
    else
        return false;
}

function recenttopicsindex_uninstall()
{
    global $mybb, $db;

    $db->query("DELETE FROM ".TABLE_PREFIX."settings WHERE name = 'recenttopicslimit'");

    rebuild_settings();
}


function recenttopicsindex_activate()
{
  require_once MYBB_ROOT."/inc/adminfunctions_templates.php";

  $returnStatus1 = find_replace_templatesets("index", "#".preg_quote('{$forums}') . "#i", '{$forums}' . "\n" . '{$recenttopics}');


}

function recenttopicsindex_deactivate()
{
  require_once MYBB_ROOT."/inc/adminfunctions_templates.php";

  $returnStatus1 = find_replace_templatesets(
  "index", "#".preg_quote('{$forums}' . "\n" . '{$recenttopics}') . "#i",
  '{$forums}',0);


}

function recenttopicsindex_show()
{
    global $db, $mybb, $page, $recenttopics, $theme, $lang, $permissioncache;

    $lang->load('recenttopicsindex');

    require_once MYBB_ROOT."inc/functions_search.php";

    if (empty($mybb->settings['recenttopicslimit']))
        $mybb->settings['recenttopicslimit'] = 10;

    $recenttopics .= '<table border="0" cellspacing="' . $theme['borderwidth'] . '" cellpadding="' . $theme['tablespace'] . '" class="tborder">
<thead>
<tr>
<td class="thead" colspan="2">

<div><strong>' . $lang->recenttopics . '</strong></div>
</td>
</tr>
</thead>';

    // Run the Query
    
    // !!! FIX private forum exposure!!!
   if ( !is_array($permissioncache) ||(is_array($permissioncache) && ((count($permissioncache)==1) && (isset($permissioncache['-1']) && ($permissioncache['-1'] = "1"))))) 
       $permissioncache = forum_permissions();

    $unsearchforums = get_unsearchable_forums();
    if($unsearchforums)
        $where_sql .= " AND t.fid NOT IN ($unsearchforums)";

    $inactiveforums = get_inactive_forums();
    if ($inactiveforums)
        $where_sql .= " AND t.fid NOT IN ($inactiveforums)";


    $query = $db->query("
    SELECT
        t.tid, t.fid, t.subject, t.lastposteruid, t.lastposter, t.lastpost, f.name
    FROM ".TABLE_PREFIX."threads as t,  ".TABLE_PREFIX."forums as f
    WHERE f.fid = t.fid AND t.fid IN(1) AND t.visible = 1 $where_sql
    ORDER BY t.lastpost DESC LIMIT " . $mybb->settings['recenttopicslimit']);
    while($threadRow = $db->fetch_array($query))
    {
        $recenttopics .= '<tr>';
        $subject = my_substr($threadRow['subject'], 0, 50);
        $subject = htmlspecialchars_uni($subject);
        $postdate = my_date($mybb->settings['dateformat'], $threadRow['lastpost']);
        $posttime = my_date($mybb->settings['timeformat'], $threadRow['lastpost']);

        $recenttopics .= '<td class="trow1">
        <a href="showthread.php?tid=' . $threadRow['tid'] . '&action=lastpost">' . $subject .'</a> '  . $lang->recenttopics_by . (!empty($threadRow['lastposteruid']) ? ' <a href="member.php?action=profile&uid=' . $threadRow['lastposteruid'] . '">' . $threadRow['lastposter'] . '</a>' : $threadRow['lastposter']) . ' (<a href="forumdisplay.php?fid=' . $threadRow['fid'] . '">' . $threadRow['name'] . '</a>)
        </td>
        <td class="trow1">' .
        $postdate . ' ' . $posttime . '
        </td>
        </tr>';
    }


    $recenttopics .= "</table><br />";



}


?>

On line 111;

WHERE f.fid = t.fid AND t.fid IN(1) AND t.visible = 1 $where_sql

Change the 1 to the forum ID you want to pull threads from.
**edit**

Trying it once more. I may have goofed. I will report back as soon as I have results.

Thanks so much

No it didnt work for me. Sad It still displays all of the new content posted, regardless of what sub forum I post it in.
Try this:

	$targetforum = 8;
    if ($targetforum)
        $where_sql .= " AND t.fid IN ($targetforum)";

Paste it under this code

    $inactiveforums = get_inactive_forums();
    if ($inactiveforums)
        $where_sql .= " AND t.fid NOT IN ($inactiveforums)";

where 8 is your forum number you want to show data from
(2012-10-19, 01:50 AM)Leefish Wrote: [ -> ]Try this:

	$targetforum = 8;
    if ($targetforum)
        $where_sql .= " AND t.fid IN ($targetforum)";

Paste it under this code

    $inactiveforums = get_inactive_forums();
    if ($inactiveforums)
        $where_sql .= " AND t.fid NOT IN ($inactiveforums)";

where 8 is your forum number you want to show data from

I will give it a go here in a few minutes and report back with the results. Thanks so much for the help and support Smile

Here is what I have, the forum ID is 185 that I want to pull from

$plugins->add_hook("index_end", "recenttopicsindex_show");

function recenttopicsindex_info()
{

    return array(
        "name"        => "Recent Topics Index Page",
        "description"        => "Adds Recent Topics to the index page",
        "website"        => "http://www.mybbhacks.com",
        "author"        => "vbgamer45",
        "authorsite"        => "http://www.mybbhacks.com",
        "version"        => "1.0.2",
        "guid"             => "3244972b3e44b82b52b12594a6af9261",
        "compatibility"    => "1*"
        );
}


function recenttopicsindex_install()
{
    global $mybb, $db;
    // Create Tables/Settings
    $db->query("INSERT  INTO ".TABLE_PREFIX."settings (sid, name, title, description, optionscode, value, disporder, gid) VALUES (NULL, 'recenttopicslimit', 'Recent Topics To Show', 'The number of recent topics you wish to display on the main index page', 'text', '10', 1, 6);");

    rebuild_settings();


}

function recenttopicsindex_is_installed()
{
    global $db;
    $query = $db->write_query("SELECT * FROM " . TABLE_PREFIX . "settings WHERE `name` = 'recenttopicslimit'");

    if($db->num_rows($query) > 0)
        return true;
    else
        return false;
}

function recenttopicsindex_uninstall()
{
    global $mybb, $db;

    $db->query("DELETE FROM ".TABLE_PREFIX."settings WHERE name = 'recenttopicslimit'");

    rebuild_settings();
}


function recenttopicsindex_activate()
{
  require_once MYBB_ROOT."/inc/adminfunctions_templates.php";

  $returnStatus1 = find_replace_templatesets("index", "#".preg_quote('{$forums}') . "#i", '{$forums}' . "\n" . '{$recenttopics}');


}

function recenttopicsindex_deactivate()
{
  require_once MYBB_ROOT."/inc/adminfunctions_templates.php";

  $returnStatus1 = find_replace_templatesets(
  "index", "#".preg_quote('{$forums}' . "\n" . '{$recenttopics}') . "#i",
  '{$forums}',0);


}

function recenttopicsindex_show()
{
    global $db, $mybb, $page, $recenttopics, $theme, $lang, $permissioncache;

    $lang->load('recenttopicsindex');

    require_once MYBB_ROOT."inc/functions_search.php";

    if (empty($mybb->settings['recenttopicslimit']))
        $mybb->settings['recenttopicslimit'] = 10;

    $recenttopics .= '<table border="0" cellspacing="' . $theme['borderwidth'] . '" cellpadding="' . $theme['tablespace'] . '" class="tborder">
<thead>
<tr>
<td class="thead" colspan="2">

<div><strong>' . $lang->recenttopics . '</strong></div>
</td>
</tr>
</thead>';

    // Run the Query
    
    // !!! FIX private forum exposure!!!
   if ( !is_array($permissioncache) ||(is_array($permissioncache) && ((count($permissioncache)==1) && (isset($permissioncache['-1']) && ($permissioncache['-1'] = "1"))))) 
       $permissioncache = forum_permissions();

    $unsearchforums = get_unsearchable_forums();
    if($unsearchforums)
        $where_sql .= " AND t.fid NOT IN ($unsearchforums)";

    $inactiveforums = get_inactive_forums();
    if ($inactiveforums)
        $where_sql .= " AND t.fid NOT IN ($inactiveforums)";
	
	$targetforum = 185;
    if ($targetforum)
        $where_sql .= " AND t.fid IN ($targetforum)";


    $query = $db->query("
    SELECT
        t.tid, t.fid, t.subject, t.lastposteruid, t.lastposter, t.lastpost, f.name
    FROM ".TABLE_PREFIX."threads as t,  ".TABLE_PREFIX."forums as f
    WHERE f.fid = t.fid AND t.fid IN(185) AND t.visible = 185 $where_sql
    ORDER BY t.lastpost DESC LIMIT " . $mybb->settings['recenttopicslimit']);
    while($threadRow = $db->fetch_array($query))
    {
        $recenttopics .= '<tr>';
        $subject = my_substr($threadRow['subject'], 0, 50);
        $subject = htmlspecialchars_uni($subject);
        $postdate = my_date($mybb->settings['dateformat'], $threadRow['lastpost']);
        $posttime = my_date($mybb->settings['timeformat'], $threadRow['lastpost']);

        $recenttopics .= '<td class="trow1">
        <a href="showthread.php?tid=' . $threadRow['tid'] . '&action=lastpost">' . $subject .'</a> '  . $lang->recenttopics_by . (!empty($threadRow['lastposteruid']) ? ' <a href="member.php?action=profile&uid=' . $threadRow['lastposteruid'] . '">' . $threadRow['lastposter'] . '</a>' : $threadRow['lastposter']) . ' (<a href="forumdisplay.php?fid=' . $threadRow['fid'] . '">' . $threadRow['name'] . '</a>)
        </td>
        <td class="trow1">' .
        $postdate . ' ' . $posttime . '
        </td>
        </tr>';
    }


    $recenttopics .= "</table><br />";



}


?>

It still pulls from any new thread I post regardless of the location. Huh

Maybe I did something wrong, thats why I posted the code for you guys to look over.
You are mixing the solutions together - open the file and from the comment //run the query to the end, paste this over the top, overwriting existing code.

    // Run the Query
    
    // !!! FIX private forum exposure!!!
   if ( !is_array($permissioncache) ||(is_array($permissioncache) && ((count($permissioncache)==1) && (isset($permissioncache['-1']) && ($permissioncache['-1'] = "1"))))) 
       $permissioncache = forum_permissions();

    $unsearchforums = get_unsearchable_forums();
    if($unsearchforums)
        $where_sql .= " AND t.fid NOT IN ($unsearchforums)";

    $inactiveforums = get_inactive_forums();
    if ($inactiveforums)
        $where_sql .= " AND t.fid NOT IN ($inactiveforums)";

	$targetforum = 185;
    if ($targetforum)
        $where_sql .= " AND t.fid IN ($targetforum)";

    $query = $db->query("
    SELECT
        t.tid, t.fid, t.subject, t.lastposteruid, t.lastposter, t.lastpost, f.name
    FROM ".TABLE_PREFIX."threads as t,  ".TABLE_PREFIX."forums as f
    WHERE f.fid = t.fid AND t.visible = 1 $where_sql
    ORDER BY t.lastpost DESC LIMIT " . $mybb->settings['recenttopicslimit']);
    while($threadRow = $db->fetch_array($query))
    {
        $recenttopics .= '<tr>';
        $subject = my_substr($threadRow['subject'], 0, 50);
        $subject = htmlspecialchars_uni($subject);
        $postdate = my_date($mybb->settings['dateformat'], $threadRow['lastpost']);
        $posttime = my_date($mybb->settings['timeformat'], $threadRow['lastpost']);

        $recenttopics .= '<td class="trow1">
        <a href="showthread.php?tid=' . $threadRow['tid'] . '&action=lastpost">' . $subject .'</a> '  . $lang->recenttopics_by . (!empty($threadRow['lastposteruid']) ? ' <a href="member.php?action=profile&uid=' . $threadRow['lastposteruid'] . '">' . $threadRow['lastposter'] . '</a>' : $threadRow['lastposter']) . ' (<a href="forumdisplay.php?fid=' . $threadRow['fid'] . '">' . $threadRow['name'] . '</a>)
        </td>
        <td class="trow1">' .
        $postdate . ' ' . $posttime . '
        </td>
        </tr>';
    }


    $recenttopics .= "</table><br />";



}

I tested this on localhost - and it worked.

Make sure the forum you are targeting is searchable and visible.
(2012-10-19, 02:52 AM)Leefish Wrote: [ -> ]You are mixing the solutions together - open the file and from the comment //run the query to the end, paste this over the top, overwriting existing code.

    // Run the Query
    
    // !!! FIX private forum exposure!!!
   if ( !is_array($permissioncache) ||(is_array($permissioncache) && ((count($permissioncache)==1) && (isset($permissioncache['-1']) && ($permissioncache['-1'] = "1"))))) 
       $permissioncache = forum_permissions();

    $unsearchforums = get_unsearchable_forums();
    if($unsearchforums)
        $where_sql .= " AND t.fid NOT IN ($unsearchforums)";

    $inactiveforums = get_inactive_forums();
    if ($inactiveforums)
        $where_sql .= " AND t.fid NOT IN ($inactiveforums)";

	$targetforum = 185;
    if ($targetforum)
        $where_sql .= " AND t.fid IN ($targetforum)";

    $query = $db->query("
    SELECT
        t.tid, t.fid, t.subject, t.lastposteruid, t.lastposter, t.lastpost, f.name
    FROM ".TABLE_PREFIX."threads as t,  ".TABLE_PREFIX."forums as f
    WHERE f.fid = t.fid AND t.visible = 1 $where_sql
    ORDER BY t.lastpost DESC LIMIT " . $mybb->settings['recenttopicslimit']);
    while($threadRow = $db->fetch_array($query))
    {
        $recenttopics .= '<tr>';
        $subject = my_substr($threadRow['subject'], 0, 50);
        $subject = htmlspecialchars_uni($subject);
        $postdate = my_date($mybb->settings['dateformat'], $threadRow['lastpost']);
        $posttime = my_date($mybb->settings['timeformat'], $threadRow['lastpost']);

        $recenttopics .= '<td class="trow1">
        <a href="showthread.php?tid=' . $threadRow['tid'] . '&action=lastpost">' . $subject .'</a> '  . $lang->recenttopics_by . (!empty($threadRow['lastposteruid']) ? ' <a href="member.php?action=profile&uid=' . $threadRow['lastposteruid'] . '">' . $threadRow['lastposter'] . '</a>' : $threadRow['lastposter']) . ' (<a href="forumdisplay.php?fid=' . $threadRow['fid'] . '">' . $threadRow['name'] . '</a>)
        </td>
        <td class="trow1">' .
        $postdate . ' ' . $posttime . '
        </td>
        </tr>';
    }


    $recenttopics .= "</table><br />";



}

I tested this on localhost - and it worked.

Make sure the forum you are targeting is searchable and visible.

Thank you SO MUCH Lee Fish!

Is there any chance you can help me do one more thing with this plugin? I know you are a busy person, but I thought I would ask.

I would like to either change the color of the text between lines (just alternating colors) or shade every other line, so that it is easier to read for the users.

Is there any easy solution for that or am I asking for too much?

I have no idea how this plugin even operates, so I do not know what variables we could easily change.