Similar Topics
Posted: 24 Mar 2010, 17:01
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:
Open viewtopic.php
Find:
Add after:
Open styles/prosilver/template/viewtopic_body.html
Find:
Before add:
Open language/en/viewtopic.php
Find:
Before add:
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:
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`);
Find:
Code: Select all
page_header($user->lang['VIEW_TOPIC'] . ' - ' . $topic_data['topic_title'], true, $forum_id);
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
Find:
Code: Select all
<!-- INCLUDE jumpbox.html -->
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 -->
Find:
Code: Select all
?>
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))