When viewing an image node(node_gallery_image), I'm trying to load CCK fields from the parent gallery node(node_gallery_gallery).

I'm doing so inside the theme.inc file and displaying inside the image navigator template(redesigned).

$variables['gallery_link'] = url('node/'. $variables['navigator']['gallery_nid']);
 
$gallery = node_load($variables['navigator']['gallery_nid']);
 
$variables['gallery_title'] = check_plain($gallery->title);
 

... Then using the code below to print out the parent gallery node title.

 <span><?php print $gallery_title; ?></span><br>

What needs to be added to my code above to access CCK fields from the parent gallery?

Comments

Prodigy’s picture

Version: 6.x-3.1 » 6.x-2.x-dev
Status: Active » Closed (fixed)

To access CCK fields of the parent gallery node, you'll need to perform a node load of $gallery and then set up whichever CCK field you need in the same format used by theme.inc. Also, I'd suggest taking the function out and doing this in your own 'custom' module or template.php.

Example:

<?php
//loading parent 
$gallery_node = node_load($gallery_nid);
// putting example cck field a variable to be used in your template for theming
$variables['gallery_example_cckfield'] = $gallery_node->field_title[0]['view'];
?>

And then inside your .tpl.php file ...

<?php print $gallery_example_cckfield; ?>