MyBB Community Forums

Full Version: Displaying recent threads
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hiya I used http://community.mybb.com/thread-62787.html to display the latest threads on my forum however it shows the threads from the staff forums which should be not viewable by anyone except staff. Is it possible to not display threads from specific forums?

Cheers Smile

~ David
this might help : RE: Lastest Forum Activity
(2011-12-29, 03:03 PM)ranjani Wrote: [ -> ]this might help : RE: Lastest Forum Activity

I have this code at the beginning:

<?php
chdir("../forum"); // path to MyBB
define("IN_MYBB", 1);
require("./global.php");
?>

and this code where I want the posts displayed:
<?php

    $query = mysql_query("
            SELECT t.*, u.username
            FROM mybb_threads t
            LEFT JOIN mybb_users u ON (u.uid=t.uid)
            WHERE 1=1 AND t.visible='1' AND t.closed NOT LIKE 'moved|%'
            ORDER BY t.lastpost DESC 
            LIMIT 0, 6" // Change the last digit to how many recent post you want to be shown
        );

    $list = '';
    while($fetch = mysql_fetch_array($query))
    {
        $list .= "<strong><a href=\"../forum/showthread.php?tid={$fetch['tid']}\">".htmlspecialchars_uni($fetch['subject'])."</a></strong><br />";
        $poster = "<a href=\"forums/member.php?action=profile&uid=".$fetch['uid']."\">{$fetch['username']}</a>";
        $list .= "Created by: {$poster}<br />";
        $list .= "<i>" .$fetch['replies']. " Replies</i>";
        $list .= "<i> , " .$fetch['views']. " Views</i><br />";
        $list .= " (<i>Last post by: " .$fetch['lastposter']. "</i>)<br /><hr width=\"50\"><br />";
    
    }
    //output
    echo $list;

?>

Cheers,

~ David
ranjani was suggesting that you scrapped that and used Dennis Tsang's little guide instead, which is better and much cleaner.
(2011-12-29, 03:21 PM)Fábio Maia Wrote: [ -> ]ranjani was suggesting that you scrapped that and used Dennis Tsang's little guide instead, which is better and much cleaner.

Hiya in the forum index.php I added code:
// get forums user cannot view
$unviewable = get_unviewable_forums(true);
if($unviewable)
{
        $unviewwhere = " AND fid NOT IN ($unviewable)";
}

        $altbg = alt_trow();
        $threadlist = '';
        $query = $db->query("
                SELECT t.*, u.username
                FROM ".TABLE_PREFIX."threads t
                LEFT JOIN ".TABLE_PREFIX."users u ON (u.uid=t.uid)
                WHERE 1=1 $unviewwhere AND t.visible='1' AND t.closed NOT LIKE 'moved|%'
                ORDER BY t.lastpost DESC
                LIMIT 0, 10"
        );
        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
                {
                        $lastposterlink = build_profile_link($thread['lastposter'], $thread['lastposteruid']);
                }
                if(my_strlen($thread['subject']) > 25)
                {
                        $thread['subject'] = my_substr($thread['subject'], 0, 25) . "...";
                }
                $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");
                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")."\";");
        } 

after
$plugins->run_hooks("index_start"); 

Then in the website I want to view the threads I put {$latestthreads}

It just displays {$latestthreads}

What did I do wrong?

Cheers Smile

~ David
where have you placed {$latestthreads} - it should work on index template ..
(2011-12-29, 03:42 PM)vernier Wrote: [ -> ]Then in the website I want to view the threads I put {$latestthreads}

What do you mean in the website? This doesn't work outside MyBB.
my forum is located in public_html/forum
My site I want it displayed on is located in public_html/v1

I put the code in the v1 index.php

Cheers Smile

~ David
(2011-12-29, 03:56 PM)Fábio Maia Wrote: [ -> ]
(2011-12-29, 03:42 PM)vernier Wrote: [ -> ]Then in the website I want to view the threads I put {$latestthreads}

What do you mean in the website? This doesn't work outside MyBB.

Sorry I meant so that the latest threads are posted on another website but not the staff forums

Cheers Smile

~ David

Then Dennis' solution won't work. You would have to connect to MyBB and tweak it a bit. And even then the table would look like your forum, which might be undesirable. So the easiest workaround is to go back to the previous setup and make this change:

1. Find:

$query = mysql_query("
        SELECT t.*, u.username
        FROM mybb_threads t
        LEFT JOIN mybb_users u ON (u.uid=t.uid)
        WHERE 1=1 AND t.visible='1' AND t.closed NOT LIKE 'moved|%'
        ORDER BY t.lastpost DESC 
        LIMIT 0, 6" // Change the last digit to how many recent post you want to be shown
);

2. Replace with:

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

$query = mysql_query("
        SELECT t.*, u.username
        FROM ".TABLE_PREFIX."threads t
        LEFT JOIN ".TABLE_PREFIX."users u ON (u.uid=t.uid)
        WHERE 1=1 $unviewwhere AND t.visible='1' AND t.closed NOT LIKE 'moved|%'
        ORDER BY t.lastpost DESC
        LIMIT 0, 10"
);
Done, thanks Fabio! Smile

~ David