MyBB Community Forums

Full Version: Conditional show after X thread?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
I want to show some code in "forum_threadlists" after 6th thread is it possible to do it with conditional?
Thanks
Since the threads aren't counted one by one in default MyBB - I don't think so. Someone correct me if I'm wrong.

You probably need a small core edit or plugin. For example try adding this after $plugins->run_hooks("forumdisplay_thread"); in forumdisplay.php:
if (!isset($threadcounter)) {
    $threadcounter = 0;
}
$threadcounter++;
Then at the end of forumdisplay_thread template:
<if ($threadcounter - 6) % $mybb->settings['threadsperpage'] == "0" then>
    ad code
</if>

Written quickly without testing so not sure if it works.
Destroy666 thank you so much for taking time trying to help me but is there a way to do it maybe with xthreads
^ the php code given by D666 can be added in a php file (eg. threadcount.php) as a plugin.
<?php
...
... ...
... ... ...
$plugins->add_hook("forumdisplay_thread", "threadcount");
...
... ...
... ... ...
function threadcount()
{
    global $mybb, $threadcounter;    
	
	//  
	if (!isset($threadcounter)) {
    $threadcounter = 0;
    }
    $threadcounter++;  		

}
?>
upload that threadcount.php file to plugins folder of MyBB files server, activate it
and add the required advertisement code with template conditional as suggested by D666
I don't think XThreads makes it more possible than default MyBB.

Either use .m.'s advice and place this code as new plugin, put it to forumdisplay.php or any plugin which hooks to forumdisplay_thread, then put the conditional in forumdisplay_thread template or use a jQuery code like this:
jQuery(document).ready(function($) {
     $("#unique_id_of_forumdisplay_table tr:eq(8)").after('<tr><td class="trow1" colspan="{$colspan}">ad code here</td></tr>');
});
no conditionals needed then but it's slower than PHP and requires conflictless jQuery. Place it in forumdisplay template between <head> and inside new <script> tag.
Destroy666 and .M. your answers the the best once thanks very much Heart all

How to make this code to show on every page after 6th thread?
<if ($threadcounter - 6) % $mybb->settings['threadsperpage'] == "0" then>
    ad code
</if>

I am sorry but it doesn't work the code just shows regarding of the thread count I have activated this plugin:
<?php
$plugins->add_hook("forumdisplay_thread", "threadcount");
function threadcount_info()
{	
	return array(
		"name" => "Forumdisplay show code after X threads",
		"description" => "You need to add IF for the code to show",
	);
}
function threadcount()
{
    global $mybb, $threadcounter;    
    
    //  
    if (!isset($threadcounter)) {
    $threadcounter = 0;
    }
    $threadcounter++;          
}
?>

And my forumdisplay_thread looks like this.
<tr>
	<td align="center" class="{$bgcolor}{$thread_type_class}" width="2%"><img src="{$theme['imgdir']}/{$folder}.gif" alt="{$folder_label}" title="{$folder_label}" /></td>
	<td align="center" class="{$bgcolor}{$thread_type_class}" width="2%">{$icon}</td>
	<td class="{$bgcolor}{$thread_type_class}">
		{$attachment_count}
		<div>
			<span>{$prefix} {$gotounread}{$thread['threadprefix']}<a href="{$thread['threadlink']}" class="{$inline_edit_class} {$new_class}" id="tid_{$inline_edit_tid}">{$thread['subject']}</a>{$thread['multipage']}</span>
			<div class="author smalltext">{$thread['profilelink']}</div>
		</div>
	</td>
	<td align="center" class="{$bgcolor}{$thread_type_class}"><a href="javascript:MyBB.whoPosted({$thread['tid']});">{$thread['replies']}</a>{$unapproved_posts}</td>
	<td align="center" class="{$bgcolor}{$thread_type_class}">{$thread['views']}</td>
	{$rating}
	<td class="{$bgcolor}{$thread_type_class}" style="white-space: nowrap; text-align: right;">
		<span class="lastpost smalltext">{$lastpostdate} {$lastposttime}<br />
		<a href="{$thread['lastpostlink']}">{$lang->lastpost}</a>: {$lastposterlink}</span>
	</td>
{$modbit}
</tr>
<if ($threadcounter - 2) % $mybb->settings['threadsperpage'] == "0" then>
    ad code
</if>

Hi can anyone please fix this code?
^ please try using table row & table cell for the required advertisement like below
<if ($threadcounter - 2) % $mybb->settings['threadsperpage'] == "0" then>
<tr class="trow1"><td colspan="{$colspan}">
    advt code 
</td></tr>
</if>
Dear .M. thanks very much for your help it shows but for some reason the thread count function doesn't work I mean it should be hidden and only show after the 2 thread!
Actually, I think this is possible with xThreads, since xThreads allows you to display a "seperator" template after a specified amount of threads in forumdisplay.
(2013-09-19, 02:35 PM)brad-t Wrote: [ -> ]Actually, I think this is possible with xThreads, since xThreads allows you to display a "seperator" template after a specified amount of threads in forumdisplay.

Please how can I do it with xThreads?
Pages: 1 2