You are here

function template_preprocess_forum_topic_navigation in Drupal 6

Preprocess variables to format the next/previous forum topic navigation links.

$variables contains $node.

See also

forum-topic-navigation.tpl.php

theme_forum_topic_navigation()

File

modules/forum/forum.module, line 897
Enable threaded discussions about general topics.

Code

function template_preprocess_forum_topic_navigation(&$variables) {
  $output = '';

  // get previous and next topic
  $sql = "SELECT n.nid, n.title, n.sticky, l.comment_count, l.last_comment_timestamp FROM {node} n INNER JOIN {node_comment_statistics} l ON n.nid = l.nid INNER JOIN {term_node} r ON n.nid = r.nid AND r.tid = %d WHERE n.status = 1 ORDER BY n.sticky DESC, " . _forum_get_topic_order_sql(variable_get('forum_order', 1));
  $result = db_query(db_rewrite_sql($sql), isset($variables['node']->tid) ? $variables['node']->tid : 0);
  $stop = $variables['prev'] = $variables['next'] = 0;
  while ($topic = db_fetch_object($result)) {
    if ($stop == 1) {
      $variables['next'] = $topic->nid;
      $variables['next_title'] = check_plain($topic->title);
      $variables['next_url'] = url("node/{$topic->nid}");
      break;
    }
    if ($topic->nid == $variables['node']->nid) {
      $stop = 1;
    }
    else {
      $variables['prev'] = $topic->nid;
      $variables['prev_title'] = check_plain($topic->title);
      $variables['prev_url'] = url("node/{$topic->nid}");
    }
  }
}