How can I put pagination on top of the forum topic, not only on the bottom of the page

Comments

michelle’s picture

Title: How can I put pagination on top of forum topic » Add pagination to top of forum topic
Version: 5.x-1.0-alpha7 » 6.x-1.x-dev
Assigned: Unassigned » michelle
Category: feature » task

Changing settings a bit because this is on my to do list.

Michelle

maulwuff’s picture

Component: Theming » Code

I did a workaround for this in D5 + advanced forum alpha12 by hacking the node.module:

my new node_show function looks like this. all changes are between #mod start and #mod end

function node_show($node, $cid) {
#mod start
  //pager on very top
  $comments_per_page = _comment_get_display_setting('comments_per_page');
  $out = comment_render($node, $cid);#needed
  $output = theme('pager', NULL, $comments_per_page, 0) ;
   $output .= node_view($node, FALSE, TRUE);
#  orig: $output = node_view($node, FALSE, TRUE);
#mod end
  if (function_exists('comment_render') && $node->comment) {
    $output .= comment_render($node, $cid);
  }

  // Update the history table, stating that this user viewed this node.
  node_tag_new($node->nid);

  return $output;
}

there may be other ways to do this, too. I found some other topics on this, too.

minesota’s picture

Subscribed

michelle’s picture

Thanks, but hacking core is not an option.

Michelle

batbug2’s picture

Yeah, I have the same request. In the mean time, I edited the comment.module (bad)

at around line 1040

  if ($num_rows && ($comment_controls == COMMENT_CONTROLS_ABOVE || $comment_controls == COMMENT_CONTROLS_ABOVE_BELOW)) {
        $output .= drupal_get_form('comment_controls', $mode, $order, $comments_per_page);
      }
  ++    $output .= theme('pager', NULL, $comments_per_page, 0);
      $output .= $comments;
      $output .= theme('pager', NULL, $comments_per_page, 0);
michelle’s picture

@batbug2 - Again, hacking core is not an option.

@all - There has to be some way of doing this without hacking core or it's not going to get done. I can't control what people do on their own sites but I will not add something to this module that requires hacking core nor will I advise others to do it. Hacking core is a bad practice that will lead to headaches.

If someone can come up with a non hacking core fix for this, great. Otherwise it will have to wait until I can figure out how to do it.

Thanks,

Michelle

michelle’s picture

Just got a clue from IRC. I don't have the time to work on this issue right now but recording it here so it doesn't get lost.

[14:49]
Michelle: Add a advanced_forum_preprocess_node() function, $vars['pager'] = theme('pager', ...); in there, and your users can probably output $pager anywhere in their node template. Alternatively, the same goes for preprocess_page().

Michelle

batbug2’s picture

itresting, gotta look into it

neyoung’s picture

Subscribed

LasseP’s picture

Status: Active » Needs work

Here is my solution.

Put this code into advanced_forum.module (function name: advanced_forum_preprocess_node)

<?php
  $mixedObj = false;
  $mixedObj->type = $variables["type"];
  $mixedObj->comments_per_page = _comment_get_display_setting('comments_per_page',$mixedObj);
  pager_query("SELECT count(*) FROM {comments} WHERE nid=".$variables["nid"], $mixedObj->comments_per_page);
?>

add this into your advf-comment-wrapper.tpl.php (before print $content);

<?php
if (isset($_GET['page']) && $_GET['page'] > 0) {
  $comments_per_page = _comment_get_display_setting('comments_per_page',$node);
  print theme('pager', NULL, $comments_per_page, 0);
}
?>

add this into your advf-forum-post.tpl.php (right after if ($top_post) { )

<?php
  $comments_per_page = _comment_get_display_setting('comments_per_page',$node); 
  print theme('pager', NULL, $comments_per_page, 0); 
?>

This is my solution.
The SQL string used for pager_query is just a simple one and can maybe be even more simpler. I just couldn't imagine of a more simpler one which can work with LIMIT #,#.

This should not be seen as a final soultion. But it works and maybe someone can find a better way to implement this completly into advf.

This has been developed with alpha13 D6. Tests with alpha15 D6 didn't work, because advf-comment-wrapper.tpl.php wasn't called.

michelle’s picture

Status: Needs work » Postponed

Thanks for your work here. I'm going to hold it over for version 2 but it will be one of the first things that I look at.

Michelle

michelle’s picture

Should note here that the bug with comment wrapper has now been fixed so this should work with the latest dev.

Michelle

LasseP’s picture

works here. D6 & alpha16 advf

AppleBag’s picture

Is it ok to add this code (lassep's #10 comment) to the latest version of advf for my d5?

DjC4’s picture

All I did was put this in my code and it worked great. I'm a php noob though and this seemed too easy so I thought I'd check here.

<?php
print theme('pager')
?>

Also when i pasted it into the page.tpl above the content it pushes down everything. I want it in line with my "post new reply" etc at the top. Do I need to create a new .php file to edit forums?

michelle’s picture

Version: 6.x-1.x-dev » 6.x-2.x-dev
Category: task » feature
Status: Postponed » Active
PetrL’s picture

Hi, I am trying to implement LasseP's fix noted in comment #10, but I have problem with advf-comment-wrapper.tpl.php part. It seems to me (I did some tests with print) that code in advf-comment-wrapper.tpl.php is not processed at all. I use default garland theme so I did not copy the *.tpl.php to theme directroy but I am changing it advanced_forum/styles/naked directory (others tpl.php changed in this directory works fine). Could you pls. help me if you see any hint.

michelle’s picture

There's a bug in Garland that keeps the preprocess from running. You need to delete the phptemplate_comment_wrapper() (off the top of my head... might not be the right function name)

Michelle

PetrL’s picture

Thanks Michelle for the info. It is realy problem of Garland. I did not want to change core so I just little bit modified the LasseP's fix noted in comment #10. Here it is for someone who would like to use it in Garland. (It is more less copy of LasseP's fix, but I put it here whole not just modified parts to avoid confusion)

in file advanced_forum.module add at the end of function advanced_forum_preprocess_node() following

$mixedObj = false;
$mixedObj->type = $variables["type"];
$mixedObj->comments_per_page = _comment_get_display_setting('comments_per_page',$mixedObj);
pager_query("SELECT count(*) FROM {comments} WHERE nid=".$variables["nid"], $mixedObj->comments_per_page);

in file advanced_forum.module add at the end of function advanced_forum_preprocess_comment()

if (($post_number % $post_per_page) == 1) {
     $variables['first_comment_on_page'] = TRUE;
}
else {
    $variables['first_comment_on_page'] = FALSE;
}

at the begining of file advf-forum-post.tpl.php add following:

 if ($first_comment_on_page) {
    $comments_per_page = _comment_get_display_setting('comments_per_page',$node);
    print theme('pager', NULL, $comments_per_page, 0);
 }
AppleBag’s picture

thanks lebloch, I just tired it and I see no effect, still no pagination at th etop of the forums, but I see the original at the bottom. Any idea what I might be missing?

PetrL’s picture

Hi AppleBag, Just one hint - this code shows pager on first page just bellow the first forum post (i.e. just above first comment of this forum post). So do not expect it at the top of the page. If it still not there, I have no idea what it can cause. It would require some reserch. For example if you add following code:

print "JUST TESTING";

at the begining of file advf-forum-post.tpl.php
Can you see the text "JUST TESTING" above each comment?

AppleBag’s picture

Ahh ok, I win the "Duh" award for the day. lol

There it is, I was looking a the very top of the threads. Works great, thanks!

michelle’s picture

Another perspective...

Though if we know the # of replies we could create a fake pager.
You just have to set the right values in $pager_total and er, whatever else it is.

Just wanted to get it recorded for now.

Michelle

ltwinner’s picture

Here's what I did to get pagination on top of topics - I put it in advanced_forum_topic_header

Add this code to advanced_forum_preprocess_advanced_forum_topic_header(&$variables)

<?php
  // Set up a pager
  $node = $variables['node'];
  $comments_per_page = _comment_get_display_setting('comments_per_page', $node);

  $query = 'SELECT COUNT(*) FROM {comments} c WHERE c.nid = ' . $node->nid;
  $result = pager_query($query, $comments_per_page, 0, NULL);
  $variables['pager'] = theme('pager', NULL, $comments_per_page, 0);
?>

Then I just used print $pager at the very start of the advanced_forum_topic_header.tpl.php file

sandino’s picture

subscribe

michelle’s picture

Status: Active » Postponed

Postponing for 3.x / D7.

Michelle

sandino’s picture

Just would like to add that advanced_forum_preprocess_advanced_forum_topic_header(&$variables) in #24 is located in file modules/contrib/advanced_forum/includes/theme.inc for Advanced Forum 6.x-2.x

RikiB’s picture

#24 works great

Steel Rat’s picture

Sandino #27, that path (modules\contrib\advanced_forum\includes\) doesn't exist anywhere I can find. Can you elaborate?

Thanks

Steel Rat’s picture

I used LasseP's code successfully, but, it only applies to forum topics, and not to comments on all content types (I'm using the AF feature of using AF styles on all comments.) So it doesn't look like AF is really treating all comments the same as comments on forum topics.

Also, on LasseP's code, with comments not on the first page, the top pager is getting placed to the right of the top comment instead of above it, causing the first comment on the page to be squished to the left.

Any ideas?

sandino’s picture

@Steel Rat

Sandino #27, that path (modules\contrib\advanced_forum\includes\) doesn't exist anywhere I can find. Can you elaborate?

Thanks

Your location my vary, because I split my 'modules' directory into 'contrib' and 'custom' subdirectories. Thus your theme.inc may be located in 'sites/all/modules/advanced_forum/includes' directory.

Steel Rat’s picture

Nope. There's no 'includes' folder under the advanced_forum installation. And no 'theme.inc' anywhere in there.

michelle’s picture

@Steel Rat: Then your install is messed up and I suggest you get a new copy.

Michelle

michelle’s picture

Status: Postponed » Closed (won't fix)

There really isn't any good way of doing this in D6. #24 works (in theory; I haven't tried it) but requires an extra query. This will be easy enough to do once we move to entities for posts in 7.x-3.x so I plan on doing it there. However, I'm not going to keep this issue because it's getting long and none of it will be relevant to this in D7.

Michelle

dunx’s picture

I know this isn't being fixed just yet, but for those willing to hack AF and are using node comments, then you'll need to change the query in #24 to:

$query = 'SELECT COUNT(*) FROM {node_comments} c WHERE c.nid = ' . $node->nid;

polluxmr2’s picture

sorry to bring an issue back from the dead but i am trying to figure out how to get what was posted in #24 to work.

I have no advanced_forum_topic_header.tpl.php to speak of. i downloaded the latest version of AF and there isn't one in there either. where should this file exist or where should i create it if it doesn't exist as part of a normal install?

DrCord’s picture

Issue summary: View changes

Did this happen in the drupal 7 version? I cannot find it as a setting...

DrCord’s picture

So this is somewhat included in the Drupal 7 version...

I went to make the change in #24 and realized from reading the function in question advanced_forum_preprocess_advanced_forum_topic_header that there was already a pager being added to the available variables it just need to be used in the template file.

I them went and copied the template file from advanced_forum in the style folder naked called advanced_forum.naked.topic-header.tpl.php to my theme's templates directory. I then added the pager to the template file like so:

  <?php
    if(isset($pager)){
      print $pager;
    }
  ?>

saved the file and cleared the cache and now I have a pager on the top of long topics, absolutely great! Thanks to all above who contributed pieces of this solution, hopefully the next person who needs to do this can now do it easily instead of with luck and magic :D