MyBB Hacks

Full Version: Show similar threads below first post
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
Hi there,

How to show Similar threads in first post only.

I added the following code (as suggested by yaldaram) below {$post} in the "showthread" template:

PHP Code:
<div id="posts">
        {$posts}
    <if ($postcounter - 1) % $mybb->settings['postsperpage'] == "0" then>
    {$similarthreads}
    </if> 
   </div> 


I also added this:

(this is suggested by Dennis Tsang)

PHP Code:
global $similarthreads;


to inc/functions_post.php.

And Similar threads table setting is enabled in ACP > Configurations > Showthread Options.

But similar threads not appearing. Any Idea?

Thanks

Instead of core editing you can use {$GLOBALS['similarthreads']}, also note that it will only show if there are any threads to be shown.
Sama34 , thank you for the tip. But I'm sure there are threads to be shown.
I noticed also (when using the code above) that similar threads are shown only in threads with one post (the OP one)
Any idea why?
Thanks
$posts is an aggregation of all posts, so if you want to stick something in the middle of them, you'd need the postbit template.

However, $similar_threads is only evaluated after posts are generated, so it probably won't work simply placing the variable there.  What you may be able to do is place this conditionally in the postbit template

HTML Code
<!-- SIMILAR_POSTS -->

and use the following in the showthread template

Code:
<?=str_replace('<!-- SIMILAR_POSTS -->', $similar_posts, $posts)?>

instead of just using {$posts}

Marvellous Yumi Yipi. It's working like a charm. I know you will have a solution for this, this is why I came here Yes

recap:

I placed this code in postbit template:

PHP Code:
<if $postcounter == "1" then>
    <!-- SIMILAR_THREADS -->
</if> 


And then I replaced:

PHP Code:
{$posts}


in showthread template

with this:

PHP Code:
<?=str_replace('<!-- SIMILAR_THREADS -->', $similarthreads, $posts)?>


Thanks Love

You may want to change:

Code:
<if $postcounter == "1" then>


With:

Code:
<if $GLOBALS['thread']['tid'] && $GLOBALS['thread']['firstpost'] == $post['pid'] then>

^ Is there much of a difference?
Probably not, just sharing what I did learn here, it is what I use since then Tongue
This:

PHP Code:
<if $GLOBALS['thread']['tid'] && $GLOBALS['thread']['firstpost'] == $post['pid'] then>


Is not working when thread has multiple pages.

Anyway thanks both for your support.

Hi could you tell me why it hides all the posts? When I use:

PHP Code:
<?=str_replace('<!-- SIMILAR_THREADS -->', $similarthreads, $posts)?>

All the posts are gone!!!

Pages: 1 2
Reference URL's