Page Titles: Ancestor, Parent, Current and Defaults

Setup page titles for different page levels using the following statement. Below example is using the Thematic WordPress Theme.

if(is_search() || is_404() || is_single()) { // target default templates 
	
	thematic_postheader(); // default header
			
} else {
	
	$parent = $post->post_parent;
	$grandparent_get = get_post($parent);
	$grandparent = $grandparent_get->post_parent;
	
	if ($post->$grandparent->post_parent) { // ancestors ?>
	
		<h1 class="entry-title"><?php echo get_the_title($grandparent); ?> | <span><?php the_title(); ?></span></h1>
	
	<?php } else if ($post->post_parent) { // parent ?>
	
		<h1 class="entry-title"><?php echo get_the_title($parent); ?> | <span><?php the_title(); ?></span></h1>
	
	<?php } else { // current ?>
	
		<h1 class="entry-title"><?php the_title(); ?></h1>

<?php }
				
}

 

Leave a Reply

katherine as a flat graphic icon

About Me

I’m an African / Ojibwe First Nations Web Developer living in Winnipeg, Manitoba.

Visit the Tips and Blog to see what I’m working on.