Theming nodes or placing CCK fields based on the viewed page
## Code needs to be updated so that it works for Drupal 6 too -- Gurpartap Singh ##
## Code by yhager; taken from http://drupal.org/node/285862 ##
When using paging with a CCK node, the it(node) can have the fields themed individually in the template file.
Paging works on the node content, and all CCK fields are visible on all pages (except for the node body that is being paged). This behavior is not always what one may want - for example, we have an image, caption, credit, deckhead and whatnot, that needs to be viewed only on the (suppose) first page of the story.
Here's what can be done to implement that:
In template.php file, create _phptemplate_variables, or add to it:
<?php
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, we 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>