hello
I have no trouble displaying the_title on a page. But can't find the tag from the codex to show the page parent. Namely, so I can create a crumb-trail, but also as several subpages from different parents have the same title.
m
hello
I have no trouble displaying the_title on a page. But can't find the tag from the codex to show the page parent. Namely, so I can create a crumb-trail, but also as several subpages from different parents have the same title.
m
will this work?
is there an easier way?
<?php
if($post->post_child)
$parent = wp_list_pages("title_li=&parent_of=".$post->post_child."&echo=0"); else
$parent = wp_list_pages("title_li=&parent_of=".$post->ID."&echo=0");
if ($parent) { ?>
<?php } ?>
$post->post_parent will give you the ID of the parent page :)
if you want to keep checking further back, you can pull the parent page and find out what it's parent is....
$parent = get_page($post->post_parent);
$grandparent = $parent->post_parent;
just thought - is there simply a crumb tag?
there isn't but there are a couple of breadcrumb plugins.
you're welcome by the way.
ivovic - would the code you posted a few weeks ago be adaptable?
<div id="breadcrumbs">
<a href="<?php echo get_bloginfo('url'); ?>" title="">Home</a>
<?php
$breadcrumbs = explode('|',get_category_parents($cat,true,'|'));
array_pop($breadcrumbs);
array_pop($breadcrumbs);
if ($breadcrumbs) foreach ($breadcrumbs as $crumb) echo ' / '.$crumb;
?>
</div>
<h1><?php single_cat_title(); ?></h1>that's for category pages... you would use that only on category archive templates.
this is what I use for breadcrumbs on my page.php and other page templates.
<div id="breadcrumbs">
<a href="<?php echo get_bloginfo('url'); ?>" title="">Home</a>
<?php
$parent_id = $post->post_parent;
$breadcrumbs = array();
while ($parent_id) {
$page = get_page($parent_id);
$breadcrumbs[] = '<a href="'.get_permalink($page->ID).'" title="">'.get_the_title($page->ID).'</a>';
$parent_id = $page->post_parent;
}
$breadcrumbs = array_reverse($breadcrumbs);
foreach ($breadcrumbs as $crumb) echo ' / '.$crumb;
?>
</div>
<h1><?php the_title(); ?></h1>since I'm posting all my code here, and you're cutting and pasting, don't you think it would just be easier to use a breadcrumb plugin? ;)
thanks - i'll try this. i wouldn't learn anything using a plugin.
thanks Ivovic - i tried that code - will have to change it a bit - but that's the tag i was looking for. shame the codex is so difficult to navigate.
yeah, there's no way I could have found that stuff in there :P
Great to have found this today! I'm super novice at PHP, but got this working, only I was wondering how it can be changed to display top level parent pages (so only one page parent title would appear - even if you are at sub sub levels of pages)
Thanks!
Awesome, thank you ivovic, can't believe this isn't posted in a more public place. A may soon combine your hierarchicial script here with ForTheLose's breadcrumbs
This topic has been closed to new replies.