Skip navigation
Sidebar -

Advanced search options →

Welcome

Welcome to CEMB forum.
Please login or register. Did you miss your activation email?

Donations

Help keep the Forum going!
Click on Kitty to donate:

Kitty is lost

Recent Posts


Qur'anic studies today
by zeca
Today at 02:45 PM

اضواء على الطريق ....... ...
by akay
Today at 12:50 PM

Do humans have needed kno...
Today at 04:17 AM

What's happened to the fo...
by zeca
Yesterday at 06:39 PM

New Britain
Yesterday at 05:41 PM

Do humans have needed kno...
Yesterday at 05:47 AM

Iran launches drones
April 13, 2024, 09:56 PM

عيد مبارك للجميع! ^_^
by akay
April 12, 2024, 04:01 PM

Eid-Al-Fitr
by akay
April 12, 2024, 12:06 PM

Lights on the way
by akay
February 01, 2024, 12:10 PM

Mock Them and Move on., ...
January 30, 2024, 10:44 AM

Pro Israel or Pro Palesti...
January 29, 2024, 01:53 PM

Theme Changer

 Topic: Next/Previous links.

 (Read 3589 times)
  • 1« Previous thread | Next thread »
  • Next/Previous links.
     OP - March 21, 2010, 08:58 AM

    These have been changed. Originally they were only available within a thread and would link to the next or previous thread.

    They are now available on any page that has a list of pages. That means topic listing in boards, recent posts pages, unread posts pages, memberlist, etc, etc.
    Rather than going to the next thread they now, of course, go to the next page of whatever you are looking at.

    This was necessary for the mobile theme since the same sources file does the page index for all themes. With the mobile theme you have no chance of hitting a tiny page number with your finger when you want the next page. A bigger link is what is needed, so that's how it's coded now.  

    Also, even on the standard sized themes when using a mouse you no longer have to select the exact number for the next page. Just roughly aim at the big "Next page" link and you're good to go. Afro

    ETA: And before anyone asks, the "Next page>>" and "<<Previous page" links will only show if there is more than one page.

    The "Next page>>" also only shows if you are not already on the last page.
    The  "<<Previous page" only shows if you are not already on the first page.

    Devious, treacherous, murderous, neanderthal, sub-human of the West. bunny
  • Re: Next/Previous links.
     Reply #1 - March 21, 2010, 09:45 AM

    Meh. Naerys told me off, damn her, so the links for next and previous threads are back as well. We have both now.  parrot

    The links for threads are at the bottom right of each thread page, just under the strip of social network icons..

    Devious, treacherous, murderous, neanderthal, sub-human of the West. bunny
  • Re: Next/Previous links.
     Reply #2 - March 21, 2010, 11:30 AM

    Thanks again for solving this. Smiley

    A little suggestion: the pipe character should be outside of the link tag.
    <a ...>&laquo; Previous thread</a> | <a ...>Next ...</a>

    German ex-Muslim forumMy YouTubeList of Ex-Muslims
    Wikis: en de fr ar tr
    CEMB-Chat
    I'm on an indefinite break...
  • Re: Next/Previous links.
     Reply #3 - March 21, 2010, 11:39 AM

    Yeah yeah yeah Tongue

    I just sorted it in the languages file. CBF'd doing it in Sources. Might do that later.

    Devious, treacherous, murderous, neanderthal, sub-human of the West. bunny
  • Re: Next/Previous links.
     Reply #4 - March 21, 2010, 11:49 AM

    I noticed a bug in including <link> tags: when there's only a next page, but no previous page, no link tag is inserted at all into the header tag. I think it's because of the if statement that checks whether certain variables are empty or not.

    German ex-Muslim forumMy YouTubeList of Ex-Muslims
    Wikis: en de fr ar tr
    CEMB-Chat
    I'm on an indefinite break...
  • Re: Next/Previous links.
     Reply #5 - March 21, 2010, 11:51 AM

    You mean the relative links in index.template? Or the page links?

    Devious, treacherous, murderous, neanderthal, sub-human of the West. bunny
  • Re: Next/Previous links.
     Reply #6 - March 21, 2010, 11:57 AM

    Yes, the relative links in the header.

    Here's the code you probably included in the template:

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

    I'll fix the code and post it here.

    German ex-Muslim forumMy YouTubeList of Ex-Muslims
    Wikis: en de fr ar tr
    CEMB-Chat
    I'm on an indefinite break...
  • Re: Next/Previous links.
     Reply #7 - March 21, 2010, 12:01 PM

    Yes that's the template code. The sources code it draws from is this bit in Sources/Display.php.

    	// 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 = db_query("
    SELECT t2.ID_TOPIC
    FROM ({$db_prefix}topics AS t, {$db_prefix}topics AS t2)
    WHERE t.ID_TOPIC = $topic" . (empty($modSettings['enableStickyTopics']) ? "
    AND t2.ID_LAST_MSG $gt_lt t.ID_LAST_MSG" : "
    AND ((t2.ID_LAST_MSG $gt_lt t.ID_LAST_MSG AND t2.isSticky $gt_lt= t.isSticky) OR t2.isSticky $gt_lt t.isSticky)") . "
    AND t2.ID_BOARD = $board
    ORDER BY" . (empty($modSettings['enableStickyTopics']) ? '' : " t2.isSticky$order,") . " t2.ID_LAST_MSG$order
    LIMIT 1", __FILE__, __LINE__);

    // No more left.
    if (mysql_num_rows($request) == 0)
    {
    mysql_free_result($request);

    // Roll over - if we're going prev, get the last - otherwise the first.
    $request = db_query("
    SELECT ID_TOPIC
    FROM {$db_prefix}topics
    WHERE ID_BOARD = $board
    ORDER BY" . (empty($modSettings['enableStickyTopics']) ? '' : " isSticky$order,") . " ID_LAST_MSG$order
    LIMIT 1", __FILE__, __LINE__);
    }

    // Now you can be sure $topic is the ID_TOPIC to view.
    list ($topic) = mysql_fetch_row($request);
    mysql_free_result($request);

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

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

      // Duplicate link!  Tell the robots not to link this.
      $context['robot_no_index'] = true;
    }

    // Add 1 to the number of views of this topic.
    if (empty($_SESSION['last_read_topic']) || $_SESSION['last_read_topic'] != $topic)
    {
    db_query("
    UPDATE {$db_prefix}topics
    SET numViews = numViews + 1
    WHERE ID_TOPIC = $topic
    LIMIT 1", __FILE__, __LINE__);

    $_SESSION['last_read_topic'] = $topic;
    }

    // Get all the important topic info.
    $request = db_query("
    SELECT
    t.numReplies, t.numViews, t.locked, ms.subject, t.isSticky, t.ID_POLL,
    t.ID_MEMBER_STARTED, t.ID_FIRST_MSG, t.ID_LAST_MSG,
    " . ($user_info['is_guest'] ? '0' : 'IFNULL(lt.ID_MSG, -1) + 1') . " AS new_from
    FROM ({$db_prefix}topics AS t, {$db_prefix}messages AS ms)" . ($user_info['is_guest'] ? '' : "
    LEFT JOIN {$db_prefix}log_topics AS lt ON (lt.ID_TOPIC = $topic AND lt.ID_MEMBER = $ID_MEMBER)") ."
    WHERE t.ID_TOPIC = $topic
    AND ms.ID_MSG = t.ID_FIRST_MSG
    LIMIT 1", __FILE__, __LINE__);
    if (mysql_num_rows($request) == 0)
    fatal_lang_error(472, false);
    $topicinfo = mysql_fetch_assoc($request);
    mysql_free_result($request);

    // The start isn't a number; it's information about what to do, where to go.
    if (!is_numeric($_REQUEST['start']))
    {
    // Redirect to the page and post with new messages, originally by Omar Bazavilvazo.
    if ($_REQUEST['start'] == 'new')
    {
    // Guests automatically go to the last topic.
    if ($user_info['is_guest'])
    {
    $context['start_from'] = $topicinfo['numReplies'];
    $_REQUEST['start'] = empty($options['view_newest_first']) ? $context['start_from'] : 0;
    }
    else
    {
    // Find the earliest unread message in the topic. (the use of topics here is just for both tables.)
    $request = db_query("
    SELECT IFNULL(lt.ID_MSG, IFNULL(lmr.ID_MSG, -1)) + 1 AS new_from
    FROM {$db_prefix}topics AS t
    LEFT JOIN {$db_prefix}log_topics AS lt ON (lt.ID_TOPIC = $topic AND lt.ID_MEMBER = $ID_MEMBER)
    LEFT JOIN {$db_prefix}log_mark_read AS lmr ON (lmr.ID_BOARD = $board AND lmr.ID_MEMBER = $ID_MEMBER)
    WHERE t.ID_TOPIC = $topic
    LIMIT 1", __FILE__, __LINE__);
    list ($new_from) = mysql_fetch_row($request);
    mysql_free_result($request);

    // Fall through to the next if statement.
    $_REQUEST['start'] = 'msg' . $new_from;
    }
    }

    // Start from a certain time index, not a message.
    if (substr($_REQUEST['start'], 0, 4) == 'from')
    {
    $timestamp = (int) substr($_REQUEST['start'], 4);
    if ($timestamp === 0)
    $_REQUEST['start'] = 0;
    else
    {
    // Find the number of messages posted before said time...
    $request = db_query("
    SELECT COUNT(*)
    FROM {$db_prefix}messages
    WHERE posterTime < $timestamp
    AND ID_TOPIC = $topic", __FILE__, __LINE__);
    list ($context['start_from']) = mysql_fetch_row($request);
    mysql_free_result($request);

    // Handle view_newest_first options, and get the correct start value.
    $_REQUEST['start'] = empty($options['view_newest_first']) ? $context['start_from'] : $topicinfo['numReplies'] - $context['start_from'];
    }
    }

    // Link to a message...
    elseif (substr($_REQUEST['start'], 0, 3) == 'msg')
    {
    $virtual_msg = (int) substr($_REQUEST['start'], 3);
    if ($virtual_msg >= $topicinfo['ID_LAST_MSG'])
    $context['start_from'] = $topicinfo['numReplies'];
    elseif ($virtual_msg <= $topicinfo['ID_FIRST_MSG'])
    $context['start_from'] = 0;
    else
    {
    // Find the start value for that message......
    $request = db_query("
    SELECT COUNT(*)
    FROM {$db_prefix}messages
    WHERE ID_MSG < $virtual_msg
    AND ID_TOPIC = $topic", __FILE__, __LINE__);
    list ($context['start_from']) = mysql_fetch_row($request);
    mysql_free_result($request);
    }

    // We need to reverse the start as well in this case.
    $_REQUEST['start'] = empty($options['view_newest_first']) ? $context['start_from'] : $topicinfo['numReplies'] - $context['start_from'];

    $context['robot_no_index'] = true;
    }
    }

    // Create a previous next string if the selected theme has it as a selected option.
    $context['previous_next'] = $modSettings['enablePreviousNext'] ? '<a href="' . $scripturl . '?topic=' . $topic . '.0;prev_next=prev#new">' . $txt['previous_next_back'] . '</a> <a href="' . $scripturl . '?topic=' . $topic . '.0;prev_next=next#new">' . $txt['previous_next_forward'] . '</a>' : '';

    Devious, treacherous, murderous, neanderthal, sub-human of the West. bunny
  • Re: Next/Previous links.
     Reply #8 - March 21, 2010, 12:08 PM

    This should do it:
      if (!empty($context['links']['next']))
        echo '<link rel="next" href="', $context['links']['next'], '" />';
      else if (!empty($context['current_topic']))
        echo '<link rel="next" href="', $scripturl, '?topic=', $context['current_topic'], '.0;prev_next=next" />';
      if (!empty($context['links']['prev']))
        echo '<link rel="prev" href="', $context['links']['prev'], '" />';
      else if (!empty($context['current_topic']))
        echo '<link rel="prev" href="', $scripturl, '?topic=', $context['current_topic'], '.0;prev_next=prev" />';

    Relative links link to the next page if available, otherwise to the next thread. The same for relative links linking to previous content.

    German ex-Muslim forumMy YouTubeList of Ex-Muslims
    Wikis: en de fr ar tr
    CEMB-Chat
    I'm on an indefinite break...
  • Re: Next/Previous links.
     Reply #9 - March 21, 2010, 12:11 PM

    Looks reasonable. Hang on a sec.  Afro

    Devious, treacherous, murderous, neanderthal, sub-human of the West. bunny
  • Re: Next/Previous links.
     Reply #10 - March 21, 2010, 12:16 PM

    Try that.

    Devious, treacherous, murderous, neanderthal, sub-human of the West. bunny
  • Re: Next/Previous links.
     Reply #11 - March 21, 2010, 12:19 PM

    Yep, works wonderfully. Afro

    German ex-Muslim forumMy YouTubeList of Ex-Muslims
    Wikis: en de fr ar tr
    CEMB-Chat
    I'm on an indefinite break...
  • Re: Next/Previous links.
     Reply #12 - March 21, 2010, 12:21 PM

    Cool. I'll post that back at SMF then since Arantor suggested the other code. Might as well do it properly. I'll sort the templates for the other themes too.

    Devious, treacherous, murderous, neanderthal, sub-human of the West. bunny
  • Re: Next/Previous links.
     Reply #13 - March 21, 2010, 01:01 PM

    Thanks again for solving this. Smiley

    A little suggestion: the pipe character should be outside of the link tag.
    <a ...>&laquo; Previous thread</a> | <a ...>Next ...</a>

    Fixed that too.  Tongue

    Devious, treacherous, murderous, neanderthal, sub-human of the West. bunny
  • 1« Previous thread | Next thread »