Page 1 of 8

Similar Topics

Posted: 24 Mar 2010, 17:01
by Post Bot
Similar Topics
Written by Tobi - Modified by Xabi and some small changes by Stoker

The Similar Topics for phpBB3 will give you a box with X similar topics at the bottom of each topic.
You can set the count of similar topics you want displayed.


First thing to do is making sure that the topics table is fulltext indexed. Execute this SQL in phpMyadmin:

Code: Select all

ALTER TABLE `phpbb_topics` ADD FULLTEXT (`topic_title`);
Open viewtopic.php
Find:

Code: Select all

page_header($user->lang['VIEW_TOPIC'] . ' - ' . $topic_data['topic_title'], true, $forum_id);
Add after:

Code: Select all

// Begin Precise Similar Topics
$sql_array = array(
   'SELECT'   => 'f.forum_id, f.forum_name, t.topic_id, t.topic_title, t.topic_time, t.topic_views, t.topic_replies, t.topic_first_poster_name, t.topic_first_poster_colour, MATCH (t.topic_title) AGAINST (\'' . $db->sql_escape($topic_data['topic_title']) . '\' ) as score',

   'FROM'      => array(
      TOPICS_TABLE   => 't',
   ),

   'LEFT_JOIN'   => array(
      array(
         'FROM'   =>   array(FORUMS_TABLE   => 'f'),
         'ON'   => 'f.forum_id = t.forum_id'
      )
   ),

   'WHERE'      => "MATCH (t.topic_title) AGAINST ('" . $db->sql_escape($topic_data['topic_title']) . "' ) >= 0.5
      AND t.topic_status <> " . ITEM_MOVED . '
      AND t.topic_time > (UNIX_TIMESTAMP() - 60*60*24*365)
      AND t.topic_id <> ' . (int) $topic_data['topic_id'],

   'GROUP_BY'   => 't.topic_id',

   'ORDER_BY'   => 'score desc',
);
$sql = $db->sql_build_query('SELECT', $sql_array);
if ($result = $db->sql_query_limit($sql, 5))
{
   while($similar = $db->sql_fetchrow($result))
   {
      if ($auth->acl_get('f_read', $similar['forum_id']))
      {
         $similar_forum_url   = append_sid("{$phpbb_root_path}viewforum.$phpEx", "f=" . $similar['forum_id']);
         $similar_topic_url   = append_sid("{$phpbb_root_path}viewtopic.$phpEx", "f=" . $similar['forum_id'] . '&t=' . $similar['topic_id']);

         $template->assign_block_vars('similar', array(
            'TOPIC_TITLE'         => $similar['topic_title'],
			'TOPIC_VIEWS'					=> $similar['topic_views'],
			'TOPIC_REPLIES'					=> $similar['topic_replies'],
			'TOPIC_TIME'                    => $user->format_date($similar['topic_time']),
			'TOPIC_FIRST_POSTER_NAME'		=> $similar['topic_first_poster_name'],
			'TOPIC_FIRST_POSTER_COLOUR'		=> $similar['topic_first_poster_colour'],
            'U_TOPIC'            => $similar_topic_url,
            'U_FORUM'            => $similar_forum_url,
            'FORUM'               => $similar['forum_name'])
         );
      }
   }
}
// End Precise Similar Topics
Open styles/prosilver/template/viewtopic_body.html
Find:

Code: Select all

<!-- INCLUDE jumpbox.html -->
Before add:

Code: Select all

<!-- IF .similar -->
<!-- IF not S_IS_BOT -->
<div class="forabg">
			<div class="inner"><span class="corners-top"><span></span></span>
			<ul class="topiclist">
				<li class="header">
					<dl>
						<dt>{L_SIM_TOP}</dt>
						<dd class="topics">{L_SIM_REP}</dd>
						<dd class="posts">{L_SIM_VIEWS}</dd>
						<dd class="lastpost"><span>{L_SIM_AUTH}</span></dd>
					</dl>
				</li>
			</ul>
<!-- ENDIF -->
			<!-- BEGIN similar -->
			<ul class="topiclist forums">
			<li class="row">
			<dl>				
				<dt><a href="{similar.U_TOPIC}" class="topictitle">{similar.TOPIC_TITLE}</a><br />{L_SIM_PIF} <a href="{similar.U_FORUM}"><strong>{similar.FORUM}</strong></a></dt>
<!-- IF not S_IS_BOT -->
				<dd class="topics">{similar.TOPIC_REPLIES}</dd>
				<dd class="posts">{similar.TOPIC_VIEWS}</dd>
				<dd class="lastpost"><span>{L_SIM_PBY}: <a style="font-weight:bold; color: #{similar.TOPIC_FIRST_POSTER_COLOUR};" href="{ROOT_PATH}memberlist.php?mode=viewprofile&un={similar.TOPIC_FIRST_POSTER_NAME}">{similar.TOPIC_FIRST_POSTER_NAME}</a><br />{similar.TOPIC_TIME}</span></dd>
<!-- ENDIF -->
			</dl>
			</li>
			</ul>
			<!-- END similar -->
<!-- IF not S_IS_BOT -->
			<span class="corners-bottom"><span></span></span></div>
</div>
<!-- ENDIF -->
<!-- ENDIF -->
Open language/en/viewtopic.php
Find:

Code: Select all

?>
Before add:

Code: Select all

// BEGIN Similar Mod
$lang = array_merge($lang, array(
	'SIM_TOP'			=> 'Similar topics',
	'SIM_REP'			=> 'Replies',
	'SIM_VIEWS'			=> 'Views',
	'SIM_AUTH'			=> 'Author',
	'SIM_PIF'			=> 'Posted in forum:',
	'SIM_PBY'			=> 'Posted by:',
));
// END Similar Mod

FAQ
Q: How do I change the number of similar topics displayed?
A: You can adjust the number in the code you added to viewtopic here:

Code: Select all

if ($result = $db->sql_query_limit($sql, 5))

Re: Similar Topics

Posted: 24 Mar 2010, 18:16
by Ashley.S.
I was about to ask about your Similar topics mod, Thanks for this Stoker

Re: Similar Topics

Posted: 24 Mar 2010, 18:19
by cisco007
nice one Stoker, this one will come in handy!

Re: Similar Topics

Posted: 24 Mar 2010, 21:22
by Widmo
This mode looks like on this site?

Re: Similar Topics

Posted: 24 Mar 2010, 21:26
by Stoker
Almost, I have 8 similar showing, this mod has 5.
But there is oinstructions how to change the similar topic count.

Re: Similar Topics

Posted: 24 Mar 2010, 22:46
by kevinviet
Thanks Stoker, work great

Re: Similar Topics

Posted: 25 Mar 2010, 14:53
by Stark
Working cool ! thanks for this !

Re: Similar Topics

Posted: 25 Mar 2010, 15:03
by Stoker
I found a tiny bug in the viewtopic_body.html part.
First post is updated.

For you who allready have installed this, find:

Code: Select all

<a href="{similar.U_FORUM}"><strong>{similar.FORUM}</strong>
Replace with:

Code: Select all

<a href="{similar.U_FORUM}"><strong>{similar.FORUM}</strong></a>

Re: Similar Topics

Posted: 27 Mar 2010, 11:21
by plasmino
very nice thanks

Re: Similar Topics

Posted: 27 Mar 2010, 16:54
by wagu
Hello very nice Stoker. One question: I Need change in spanish some parts. Where Can I modify in this MOD? :D
In this part: Similar Topics, Replies, views, author:

Image