MyBB Community Forums

Full Version: Display latest threads on index
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
hi

i want to fetch only the thread titles and its link from the portal page and display them on the index page inside a marquee...

can anyone guide me the right hooks and codes to be used to achieve this....

i guess the following quesry will fetch me the latest threads from the db, where $max will the number of threads i want to display...
$latest = $db->query("SELECT * FROM ".TABLE_PREFIX."threads ORDER BY `tid` DESC LIMIT $max");

but i am not sure how to incorporate this code to the index page... Huh


thanks in advance Smile
you can try code from here or here (see also replies on the threads)

there are more threads on this community with the guidance for your above requirement
plugins also exist (eg. Recent Topics on Index page)
yes i have seen quite a few TUTs and plugins regarding this, but most of them fetches the latest posts rather than latest threads...

for ex, i post a new thread tid=100 and another member posts another new tid=101 and another member posts a reply to an existing tid=20... now i want only the tid100 and 101 to be displayed and not the reply to old thread...

i do not want the replies to be fetched as a new topic... i want only the new threads to be displayed
tid will fetch the threads only, not replies. Replies are called referring pid.

The hook to include is "index_start". Example:

$plugins->add_hook("index_start", "threadlist_function");
here is a simple plugin like code for your requirement. [attachment=29643]
you can add latestthreads.php in plugins folder, activate and add {$latestthreads} on index template

 $max = 10;
	
	$query = $db->query("SELECT * FROM ".TABLE_PREFIX."threads ORDER BY `tid` DESC LIMIT $max"); 
    $latestthreads = '<marquee scrollamount=3>';
	while($result = $db->fetch_array($query))
		{
        $latestthreads .= "*&nbsp;<a href=\"showthread.php?tid={$result['tid']}\">".htmlspecialchars_uni($result['subject'])."</a>";
        $latestthreads .= "&nbsp;&nbsp;";
    	}
		$latestthreads .= '</marquee>';
		
		return $latestthreads;
(2013-06-29, 09:58 AM).m. Wrote: [ -> ]here is a simple plugin like code for your requirement.
you can add latestthreads.php in plugins folder, activate and add {$latestthreads} on index template

HeartHeartHeart

works like a charm on localhost... will do some modifications and css additions before taking it to live Smile thanks again Smile

its now added to my site... works perfectly Heart

follow my siggy to check it Big Grin
(2013-06-29, 09:58 AM).m. Wrote: [ -> ]here is a simple plugin like code for your requirement.
you can add  latestthreads.php in plugins folder, activate and add {$latestthreads} on index template



 $max = 10;
 
 $query = $db->query("SELECT * FROM ".TABLE_PREFIX."threads ORDER BY `tid` DESC LIMIT $max"); 
    $latestthreads = '<marquee scrollamount=3>';
 while($result = $db->fetch_array($query))
 {
        $latestthreads .= "*&nbsp;<a href=\"showthread.php?tid={$result['tid']}\">".htmlspecialchars_uni($result['subject'])."</a>";
        $latestthreads .= "&nbsp;&nbsp;";
     }
 $latestthreads .= '</marquee>';
 
 return $latestthreads;

Mybb 1.8.1

Where do I add this code

How do I get to be like that here in a ?

http://thegame-zone.com/index.php