Expose a "current page" variable for themes
| Project: | Paging |
| Version: | 6.x-1.0-beta3 |
| Component: | Code |
| Category: | feature request |
| Priority: | normal |
| Assigned: | Unassigned |
| Status: | closed |
| Issue tags: | current page, pagination, theme |
Jump to:
I'm not sure if the module already offers this, but I couldn't find anything in the code or $node object that fit the bill.
Problem: I've got a custom content type with some CCK fields, and I want some of these to appear only on the first page. From a theme perspective, I can't seem to be able to figure out how to find out what the current page is in a clean way, unless I'm missing something. (Can I get at it using the arg() function?)
Possible solution(?): In _paging_nodeapi(), the "view" case, the current page is already being found in order to populate the $node->content['body']['#value']. The section looks like:
<?php
global $pager_page_array, $pager_total;
$pager_page_array = explode(',', $page);
$pager_total[$element] = $node->page_count;
$page = isset($pager_page_array[$element]) ? $pager_page_array[$element] : 0;
// Put the current page contents into the node body.
$node->content['body']['#value'] = check_markup($node->pages[$page], $node->format, FALSE);
?>$page equates to the current page you're on. (starting at 0) I thought it would be useful/clean to just drop that value into the $node object.
<?php
global $pager_page_array, $pager_total;
$pager_page_array = explode(',', $page);
$pager_total[$element] = $node->page_count;
$page = isset($pager_page_array[$element]) ? $pager_page_array[$element] : 0;
// Put the current page contents into the node body.
$node->content['body']['#value'] = check_markup($node->pages[$page], $node->format, FALSE);
$node->page_current = $page;
?>That way I can check the var in my theme and show content appropriately.
If there's another way of doing this, without modifying the module, I'd love to hear it. Otherwise, if it seems useful to have this, then maybe introduce it in the next release? $node->$page_count already exists.
Cheers!

#1
<?phpprint substr($_GET['page'], (strpos($_GET['page'], ',') + 1)); // gives you the current page :)
?>
#2
Ugh, thanks. I blame my tendency to over think. :P
Still, a
$node->page_currentvar would be themer friendly, especially for those developers who aren't really up on their PHP.#3
http://drupal.org/cvs?commit=198802
Thanks!
#4
Automatically closed -- issue fixed for 2 weeks with no activity.