Uutiset:

Want to get involved in developing SMF, then why not lend a hand on our github!

Main Menu
Advertisement:

Prev_next (Previous Next) links with topic titles

Aloittaja MiY4Gi, lokakuu 25, 2011, 07:43:48 AP

« edellinen - seuraava »

MiY4Gi

I want the prev_next links on the topic pages to have the previous/next topics titles instead of just the words "previous" and "next", just like it is done in blogs.

I've got SMF 2.0.1.

The mod should have the same layout as the Previous & Next Link Enhancements mod, with the only difference being that the words "previous" and "next" should be replaced with their corresponding thread titles.

In the index.template.php file I found this related code.


// If we're viewing a topic, these should be the previous and next topics, respectively.
if (!empty($context['current_topic']))
echo '
<link rel="prev" href="', $scripturl, '?topic=', $context['current_topic'], '.0;prev_next=prev" />
<link rel="next" href="', $scripturl, '?topic=', $context['current_topic'], '.0;prev_next=next" />';


In the display.php file I found this related code, which I suspect fetches the previous/next topics information:


// Find the previous or next topic.  Make a fuss if there are no more.
if (isset($_REQUEST['prev_next']) && ($_REQUEST['prev_next'] == 'prev' || $_REQUEST['prev_next'] == 'next'))
{
// No use in calculating the next topic if there's only one.
if ($board_info['num_topics'] > 1)
{
// Just prepare some variables that are used in the query.
$gt_lt = $_REQUEST['prev_next'] == 'prev' ? '>' : '<';
$order = $_REQUEST['prev_next'] == 'prev' ? '' : ' DESC';

$request = $smcFunc['db_query']('', '
SELECT t2.id_topic
FROM {db_prefix}topics AS t
INNER JOIN {db_prefix}topics AS t2 ON (' . (empty($modSettings['enableStickyTopics']) ? '
t2.id_last_msg ' . $gt_lt . ' t.id_last_msg' : '
(t2.id_last_msg ' . $gt_lt . ' t.id_last_msg AND t2.is_sticky ' . $gt_lt . '= t.is_sticky) OR t2.is_sticky ' . $gt_lt . ' t.is_sticky') . ')
WHERE t.id_topic = {int:current_topic}
AND t2.id_board = {int:current_board}' . (!$modSettings['postmod_active'] || allowedTo('approve_posts') ? '' : '
AND (t2.approved = {int:is_approved} OR (t2.id_member_started != {int:id_member_started} AND t2.id_member_started = {int:current_member}))') . '
ORDER BY' . (empty($modSettings['enableStickyTopics']) ? '' : ' t2.is_sticky' . $order . ',') . ' t2.id_last_msg' . $order . '
LIMIT 1',
array(
'current_board' => $board,
'current_member' => $user_info['id'],
'current_topic' => $topic,
'is_approved' => 1,
'id_member_started' => 0,
)
);

// No more left.
if ($smcFunc['db_num_rows']($request) == 0)
{
$smcFunc['db_free_result']($request);

// Roll over - if we're going prev, get the last - otherwise the first.
$request = $smcFunc['db_query']('', '
SELECT id_topic
FROM {db_prefix}topics
WHERE id_board = {int:current_board}' . (!$modSettings['postmod_active'] || allowedTo('approve_posts') ? '' : '
AND (approved = {int:is_approved} OR (id_member_started != {int:id_member_started} AND id_member_started = {int:current_member}))') . '
ORDER BY' . (empty($modSettings['enableStickyTopics']) ? '' : ' is_sticky' . $order . ',') . ' id_last_msg' . $order . '
LIMIT 1',
array(
'current_board' => $board,
'current_member' => $user_info['id'],
'is_approved' => 1,
'id_member_started' => 0,
)
);
}

// Now you can be sure $topic is the id_topic to view.
list ($topic) = $smcFunc['db_fetch_row']($request);
$smcFunc['db_free_result']($request);

$context['current_topic'] = $topic;
}

// Go to the newest message on this topic.
$_REQUEST['start'] = 'new';
}


And here's the code that actually display's the prev_next links in the topic page:


// Create a previous next string if the selected theme has it as a selected option.
$context['previous_next'] = $modSettings['enablePreviousNext'] ? '<br /><div style="text-align:center"><a href="' . $scripturl . '?topic=' . $topic . '.0;prev_next=prev#new">' . $txt['previous_next_back'] . '</a>  |  <b><a href="' . $scripturl . '?board=' . $board . '.0">' . $board_info['name'] . '</a></b>  |  <a href="' . $scripturl . '?topic=' . $topic . '.0;prev_next=next#new">' . $txt['previous_next_forward'] . '</a></div><br />' : '';
Check out my new website, MyAnimeClub.net. I plan to create the largest anime community, and most fun and user-friendly anime forum in the world. It's still in the development stage though.

Advertisement: