I have not figured out how to do this - I know the breadcrumb does this, but my interest is to print the title of the parent node in the body of the child node.

A view would be fine, and it seems like this may already be a feature (which is why I'm labeling this issue as a support request instead of a feature request) but please let me know if I'm wrong about that.

If this exists, how do it do it?

Thanks in advance!
Scott

Comments

ronan’s picture

If you're comfortable with templates and a little php, what I do is use node_load to load the parent node within the template and display the title from that:

within the node-xxxx.tpl.php file

  $parent = node_load( $node->parent );
  echo $parent->title;

hope this helps
R

scottrigby’s picture

This works great ronan - thanks so much!

ronan’s picture

Status: Active » Closed (fixed)
planctus’s picture

Does anybody know how to show the parent title in a children nodes view as the view title?
This is going me crazy, nodehierarchy is great but when i choose to build a view as a separate page using the parent node id as the view argument i'm not able to print the parent title as the view title, so i have childrens being shown but nobody sees which node they belong to.
I added the parent field in the children view, but it's not the same, i would like to have the parent title as the page title..
I've tried using php in view header to get the parent title and show it but it didn't work...
Thanks,
Da.

planctus’s picture

how stupid am i?
that was easy...i had to use the %1 in the view title.
Thanks, i don't know it this happens to someone else...but when i write something like an issue here on drupal.org usually i find the solution by myself in a short time :-)
Don't know why...
Da.

7immy’s picture

Version: 5.x-1.x-dev » 6.x-1.0

hi, sorry to bring this post back up but i cant seem to get this to work. I've tried adding it to "node.tpl.php" but nothing shows up? dont know if this makes a difference but I'm using version 6 and the original poster is using version 5.

this is the closest I've come to in finding a way to add the parent title to a child page.

please help
thanks

jphelan’s picture

I get an error when I use the code above. I'm using 5.12, do I need to change something?

stefan81’s picture

Version: 6.x-1.0 » 6.x-1.2
Priority: Critical » Normal
Status: Closed (fixed) » Active

Dear 7immy,
Did you find a solution for version 6.x?

ronan’s picture

I don't see why that code wouldn't still work with the 6.x-1.x branch. Let me know if it isn't.

stefan81’s picture

Hi, I inserted the code you suggested above, but nothing happens.

  $parent = node_load( $node->parent );
  echo $parent->title;

I would be very useful to me if the title of the parent node can be called from page.tpl.php

ESBertrand’s picture

Here's a workable method to use for 6.x and later:

http://drupal.org/node/301262#comment-2502090

Erik

asb’s picture

Hi,

I tried using the snippet from #1 in custom-pager.tpl.php (from Custom Pager), and I'm getting the parent title - but it's not hyperlinked. If I'm putting the print statement in l(), I'm getting a link to the website root page (sorry, no coding experience).

<?php
  $parent = node_load( $node->parent );
  echo l($parent->title);
?>

Is it possible to get a link on the parent title? That would allow to mimic the 'book' module's behaviour a bit more...

Thanks & greetings, -asb

isaac.niebeling’s picture

Try

  $parent = node_load($node->parent);
  echo l($parent->title, 'node/' . $node->parent); 

Right now, you're not giving l (the link function) a path to go to, just a title -- more info on the function is at http://api.drupal.org/api/function/l/6

asb’s picture

Thanks, Isaac,

indeed, this does work! ;)

Full custom-pager.tpl.php, if someone needs it:

<div class="clear"></div>
<ul class="custom-pager custom-pager-<?php print $position; ?>">
  <li class="noborder"><?php print t('Browse').': '?></li>
  <?php if (! empty($first)) { ?>
    <li class="first"><?php print $first; ?></li>
  <?php } ?>
  <?php if (! empty($previous)) { ?>
    <li class="previous"><?php print $previous; ?></li>
  <?php } ?>
  <?php if (! empty($key)) { ?>
    <li class="key">
      <?php $parent = node_load( $node->parent );
        echo l($parent->title, 'node/' . $node->parent); ?>
      <?php print $key; ?></li>
  <?php } ?>
  <?php if (! empty($next)) { ?>
    <li class="next"><?php print $next; ?></li>
  <?php } ?>
  <?php if (! empty($last)) { ?>
    <li class="last"><?php print $last; ?></li>
  <?php } ?>
</ul>

That will result in a Custom Pager like

Browse: First page - Previous page - <parent node> 2 of 10 - Next page - Last page

Thanks again & greetings,
-asb

asb’s picture

Version: 6.x-1.2 » 6.x-2.x-dev

The template from #14 seems to no longer work with 6.x-2.x-dev, or it doesn't work with secondary parents, or something else is broken, or it's just me ;-(

asb’s picture

Component: User interface » Drupal/PHP Code

...and it's working again in 6.x-2.1, so I think this can be closed. Please reopen if issue still exists for you.

asb’s picture

Status: Active » Closed (fixed)