In most forum software, the thread list has a pager next to it. For example, in the thread list you'll see something like this:

My Thread 1, 2, 3

Where 1, 2, and 3 are links to pages of that thread. Is there a way to accomplish this in Drupal? I've spent all afternoon poking around but no luck (yet.)

Also: I'd also like a way for the pagers inside a thread to appear at both the TOP and bottom of the page, not just the bottom. I've seen Drupal sites do this, and I'd like to know the secret.

If it makes a difference, I'm using flat threads with flatforum.module.

Comments

MrEricSir’s picture

Unfortunately I had to write my own pager. But hey, it works.

With a phptemplate theme, add this to template.php:

***** CODE DELETED ***** (see below)

As you can see, the additions to the code (1) fetches the value for comments_per_page and (2) computes page number links.

MrEricSir’s picture

Turns out that last version was buggy. Seems to be fine now.

Important note: this is for the 4.6 series ONLY. I have submitted a patch for 4.7's forum.module which does the same. (The difference lies in ?from= vs ?page= )

<?php

function phptemplate_forum_topic_list($tid, $topics, $sortby, $forum_per_page) {
  global $forum_topic_list_header;

  // fetch globals
  $comments_per_page = variable_get('comments_per_page', 30);

  if ($topics) {

    foreach ($topics as $topic) {
      // folder is new if topic is new or there are new comments since last visit
      if ($topic->tid != $tid) {
        $rows[] = array(
          array('data' => theme('forum_icon', $topic->new, $topic->num_comments, $topic->comment_mode, $topic->sticky), 'class' => 'icon'),
          array('data' => check_plain($topic->title), 'class' => 'title'),
          array('data' => l(t('This topic has been moved'), "forum/$topic->tid"), 'colspan' => '3')
        );
      }
      else {
        $comments_per_page = $_GET['comments_per_page'];
        if (empty($comments_per_page)) {
          $comments_per_page = $user->comments_per_page ? $user->comments_per_page : ($_SESSION   ['comment_comments_per_page'] ? $_SESSION['comment_comments_per_page'] : variable_get('comment_default_per_page', '50'));
        }
        // compute page_links
        $page_links = null; // clear html output
        if ($topic->num_comments > $comments_per_page) {
          $num_comment_pages = ceil( $topic->num_comments / $comments_per_page );
          // iterate
          for ($page_number = 1; $page_number <= $num_comment_pages; $page_number++) {
            if ($page_number != 1) {
              $page_links .= ', ';  // commas separate page numbers
            }
            $page_links .= l($page_number,
                            "node/$topic->nid",
                            null,
                            'from='.($page_number - 1) * $comments_per_page.
                            '&comments_per_page='.$comments_per_page
                             );
          }
         $page_links = ' [ '.$page_links.' ]';  // add brackets
        }

			// this forum topic row
        $rows[] = array(
          array('data' => theme('forum_icon', $topic->new, $topic->num_comments, $topic->comment_mode, $topic->sticky), 'class' => 'icon'),
          array('data' => l($topic->title, "node/$topic->nid").$page_links, 'class' => 'topic'),

          array('data' => $topic->num_comments . ($topic->new_replies ? '<br />'. l(format_plural($topic->new_replies, '1 new', '%count new'), "node/$topic->nid", NULL, NULL, 'new') : ''), 'class' => 'replies'),
          array('data' => _forum_format($topic), 'class' => 'created'),
          array('data' => _forum_format($topic->last_reply), 'class' => 'last-reply')
        );


      }
    }
  }

  $output .= theme('table', $forum_topic_list_header, $rows);
  $output .= theme('pager', NULL, $forum_per_page, 0, tablesort_pager());

  return $output;
}

?>