MyBB Community Forums

Full Version: Lastest Forum posts and announcement
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi

guys i use last threads cods from here and its work perfectly

i need the same code to show last posts and other one to show last forums announcement.

thank you

pleas someone help me Thank you.
Assuming that you know WHERE & HOW to put this code, (Its just like the ont you did for Latest Threads, follow the same steps, just the code is different Wink)

Change the code you replaced earlier incase of LATEST threads to:

// 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, u.displaygroup, u.avatar, u.usergroup, u.avatardimensions, f.name AS forumname, lp.avatar as lpavatar, t.username AS threadusername
                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 $unviewwhere AND t.visible='1' AND t.closed NOT LIKE 'moved|%' AND t.poll > 0 
                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($thread['lpavatar'])
        {
        $thread['lpavatar'] = htmlspecialchars_uni($thread['lpavatar']);
        }
        else
        {
        $thread['lpavatar'] = $mybb->settings['bburl']."/images/default_avatar.gif"; $thread['avatardimensions'] = "45|45";
        } 
                if(my_strlen($thread['subject']) > 100)
                {
                        $thread['subject'] = my_substr($thread['subject'], 0, 100) . "...";
                }
                $thread['subject'] = htmlspecialchars_uni($thread['subject']);
                $thread['threadlink'] = get_thread_link($thread['tid']);
                $thread['lastpostlink'] = get_thread_link($thread['tid'], 0, "lastpost");
                $thread['username'] = $thread['threadusername'];
                $threadstarter = build_profile_link($thread['username'], $thread['uid']);
                $threadender = build_profile_link($thread['lastposter'], $thread['lastposteruid']);
                $thread['profilelink'] = $thread['threadusername'];    
                eval("\$threadlist .= \"".$templates->get("portal_latestpolls_poll")."\";");
                $altbg = alt_trow();
                
                
        }
        if($threadlist)
        {
                // Show the table only if there are threads
                eval("\$latestposts = \"".$templates->get("latestposts")."\";");
        } 
        



Now you have pulled out all the required stuff Big Grin

Create a new template, name it "latestposts". Enter your HTML code as required.

All the variables you can use here:

{$thread['subject']} = Threads Subject
{threadstarter} = Thread Starter
{threadender} = The Last Poster
{$thread['lastpostlink']} = Last Post LINK, use it as <a href="{$thread['lastpostlink']}">{$thread['subject']}</a>
{$thread['lpavatar']} = Last Posters Avatar
{$thread['lastposter']} = Last Posters USERNAME Only
{$thread['threadlink']} = Main Thread LINK

Enjoy Wink
Thank you for help but its not show last posts????

I need like this :

[Image: xx13fvvso02euk2mfg6d.png]
Hmm.... you need some of the text of the Lastpost also... I don't have a good idea on how to do that.... Give me some time .. I will check & try to write some codes for you.... hopefully!

I think I found it.

Go to your cPanel, Open index.php, find:
$plugins->run_hooks("index_start"); 

After that, add:

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

        $altbg = alt_trow();
        $threadlist = '';
        $msgquery = $db->query("
            SELECT p.message AS lastpostmessage, p.dateline, p.tid
            FROM ".TABLE_PREFIX."posts p
            WHERE p.tid='$tid'
            $visible
            ORDER BY p.dateline
        ");
        while($post = $db->fetch_array($msgquery))
        {
           if(my_strlen($post['lastpostmessage']) > 100)
           {
                        $post['lastpostmessage'] = my_substr($thread['subject'], 0, 100) . "...";
           }
           $lpmessage = $post['lastpostmessage'];
        }
        $query = $db->query("
                SELECT t.*, u.username, u.displaygroup, u.avatar, u.usergroup, u.avatardimensions, f.name AS forumname, lp.avatar as lpavatar, t.username AS threadusername
                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 $unviewwhere AND t.visible='1' AND t.closed NOT LIKE 'moved|%' AND t.poll > 0
                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($thread['lpavatar'])
        {
        $thread['lpavatar'] = htmlspecialchars_uni($thread['lpavatar']);
        }
        else
        {
        $thread['lpavatar'] = $mybb->settings['bburl']."/images/default_avatar.gif"; $thread['avatardimensions'] = "45|45";
        }
                if(my_strlen($thread['subject']) > 25)
                {
                        $thread['subject'] = my_substr($thread['subject'], 0, 25) . "...";
                }
                $thread['subject'] = htmlspecialchars_uni($thread['subject']);
                $thread['threadlink'] = get_thread_link($thread['tid']);
                $thread['lastpostlink'] = get_thread_link($thread['tid'], 0, "lastpost");
                $thread['username'] = $thread['threadusername'];
                $threadstarter = build_profile_link($thread['username'], $thread['uid']);
                $threadender = build_profile_link($thread['lastposter'], $thread['lastposteruid']);
                $thread['profilelink'] = $thread['threadusername'];    
                eval("\$postlist .= \"".$templates->get("latestposts_posts")."\";");
                $altbg = alt_trow();
                
                
        }
        if($postlist)  //To make sure BLANK stuff ain't displayed,\.
        {
                // Show the table only if there are threads
                eval("\$latestposts = \"".$templates->get("latestposts")."\";");
        }

One again,

Create two new templates, name them as "latestposts" & "latestposts_posts".

In latestposts_posts the content you are putting in a PARTICULAR box comes.
Where as in latestposts the whole TABLE containing the Latestpost boxes comes.
You must put {$postlist} in your "latestposts" template to pull out the Boxes.

All variables you might need in achieving are:

{$thread['subject']} = Threads Subject
{threadstarter} = Thread Starter
{threadender} = The Last Poster
{$thread['lastpostlink']} = Last Post LINK, use it as <a href="{$thread['lastpostlink']}">{$thread['subject']}</a>
{$thread['lpavatar']} = Last Posters Avatar
{$thread['lastposter']} = Last Posters USERNAME Only
{$thread['threadlink']} = Main Thread LINK
{$lpmessage} = The last post message