pages

14 posts / 0 new
Last post
magnifico
Offline
Joined: 29-11-05
Apr 13 2007 15:54
pages

could we have a thing like on the old forums where when you click on a thread you get the choice of which page to go to, rather than just having to go to the first page, scroll all the way down and then click on the page number each time?

Jacques Roux's picture
Jacques Roux
Offline
Joined: 17-07-06
Apr 13 2007 19:06

Yeah i think its something we have to work on, perhaps Felix Frost can help us with.

Felix Frost's picture
Felix Frost
Offline
Joined: 30-12-05
Apr 15 2007 14:50

No problem. Try this:

In comments.module:

/**
 * New function to make links to all pages of comments.
 */

function comment_page_links($num_comments, $nid) {
  $comments_per_page = _comment_get_display_setting('comments_per_page');
  $pagenum = intval($num_comments / $comments_per_page);
  $pagelinks = NULL;
  if ($pagenum > 0) {
    $pagelinks = '<br />[page ' . l("1", "node/$nid");
    if ($pagenum < 10) {
      $start = 1;
    }
    else {
      $start = $pagenum - 8;
      $pagelinks .= ',...';
    }
    for ($i = $start; $i < $pagenum; $i++) {
      $pagelinks .= ', ' . l($i+1, "node/$nid", NULL,"page=$i");
      }
    $pagelinks .= ']';
    }
  return $pagelinks;
}

In tracker.module, in function tracker_page:

replace the line

l($node->title, "node/$node->nid") .' '. theme('mark', node_mark($node->nid, $node->changed)),

with

l($node->title, "node/$node->nid") .' '. theme('mark', node_mark($node->nid, $node->changed)) . comment_page_links($node->comment_count, $node->nid),

This is only for the tracker page, but we can call on our new function from the forum and forum/tracker pages also. I'll have to get back to you on that, though.

Jacques Roux's picture
Jacques Roux
Offline
Joined: 17-07-06
Apr 15 2007 16:11

Works great - thanks as usual FF!

Not on at the moment because i am trying not to hack tracker.module. tried putting function tracker page in its own module (catch - pagenumbers) but its not working atm.

back later

Mike Harman
Offline
Joined: 7-02-06
Apr 15 2007 20:35

Wondering if it'd work as a standalone view field, either in a module or as a .inc in views - then we can override all the trackers with views and put it in there.

Not sure how to do view fields yet though.

Jacques Roux's picture
Jacques Roux
Offline
Joined: 17-07-06
Apr 16 2007 22:29

Ok i see where i was going wrong. You can override module functions which arent 'theme' functions.

So this function cant be put in its own module - has to be hardcoded in.

Catch - if u can figure out what u mean above then they might be a long term solution.

Jacques Roux's picture
Jacques Roux
Offline
Joined: 17-07-06
Apr 16 2007 22:50

Ok think there is a problem for this:

On threads with two pages the tracker is only showing:

Quote:
London libcom drinks - 13th April - Shoreditch
[page 1]

And both the page 1 link and the title link to the same page (the first page) and it doesn't recognise the 2nd. But if a thread actually only has one page it doesnt show the [page 1]

Felix Frost's picture
Felix Frost
Offline
Joined: 30-12-05
Apr 17 2007 16:00

Seems like it counts one page to little.
Just change the line

for ($i = $start; $i < $pagenum; $i++) {

to

for ($i = $start; $i <= $pagenum; $i++) {

and you should be OK.

Felix Frost's picture
Felix Frost
Offline
Joined: 30-12-05
Apr 17 2007 17:27

I don't know how to add new fields to views, but you can add this to the existing 'Node: Title' field:

In view_node.inc, function views_handler_field_nodelink

replace

return l($value, "node/$data->nid");

with

  $num_comments = comment_num_all($data->nid);
  $output = l($value, "node/$data->nid");
  $output .= comment_page_links($num_comments, $data->nid);
  return $output;
Jacques Roux's picture
Jacques Roux
Offline
Joined: 17-07-06
Apr 17 2007 19:02

catch - we dont have views for forums right? So have to do that in code not module?

Felix Frost's picture
Felix Frost
Offline
Joined: 30-12-05
Apr 18 2007 16:34

I noticed that it's also counting one comment to many.
You can fix it by replacing

$pagenum = intval($num_comments / $comments_per_page);

with

$pagenum = intval(($num_comments - 1) / $comments_per_page);

Felix Frost's picture
Felix Frost
Offline
Joined: 30-12-05
Apr 18 2007 20:05

And finally, for the forum module, in the function theme_forum_topic_list:

replace the line

array('data' => l($topic->title, "node/$topic->nid"), 'class' => 'topic'),

with

array('data' => l($topic->title, "node/$topic->nid") . comment_page_links($topic->num_comments, $topic->nid), 'class' => 'topic'),

Jacques Roux's picture
Jacques Roux
Offline
Joined: 17-07-06
Apr 18 2007 23:15
Felix Frost wrote:
I noticed that it's also counting one comment to many.

Done this. Not the other yet.

Catch - u see my post above?

Mike Harman
Offline
Joined: 7-02-06
Apr 19 2007 11:46

individual forum indexes we don't have views for. thinking about it though, that might be something we could override - especially if we did a manual main forums index..