I am using paging with a CCK node, that has the fields themed individually in the template file.
Paging works on the node content, so all fields are visible on all pages (except for the node body that is being paged). This behavior is not always what I want - for example, I have an image, caption, credit, deckhead and whatnot, that I want to be viewed only on the first page of the story.
Here's what I did to implement that - I think it should be documented, since I assume this would be a common need.
In template.php file, create _phptemplate_variables, or add to it:
function _phptemplate_variables($hook, $vars = array()) {
if ($hook == 'node') {
if (module_exists('paging')) {
$page = isset($_GET['page']) ? $_GET['page'] : '';
$pager_page_array = explode(',', $page);
$vars['page'] = isset($pager_page_array[1]) ? $pager_page_array[1] : 0;
}
}
return $vars;
}
Then, to show the image on the first page only, I have in node.tpl.php (or node-mycontenttype.tpl.php:
<?php if (!$page): /* viewing the first page */?>
<?php print $field_image[0]['view']; ?>
<?php endif; ?>
<div class="body"><?php print $node->content['body']['#value'] ?></div>
Of course, if there is a better way to implement that, I'll be happy to know about it!
Comments
Comment #1
Gurpartap Singh commentedThat's enough to be good. You can include this guide in the handbooks (http://drupal.org/node/360809) as well. :)
Comment #2
Gurpartap Singh commentedCan you post your latest working example in the handbooks? A simple page with one or two sentences of explanation with code would be more than enough. :)
Comment #3
Gurpartap Singh commentedDone.
Comment #4
yhager commentedOops.. you were faster than me. Thanks.
My code is for 5.x, I have yet to test it on 6.x.
Comment #5
Gurpartap Singh commentedyes, I have mentioned the same on the page. Would love a Drupal 6 update :)