Display the top level category in WordPress

By Tim Priebe on July 16, 2009 at 12:00 pm in Development,How-To,Technical

Wordpress LogoThe is just a quick WordPress code snippet for those WordPress programmers or code dabblers out there.

Recently we needed a page in WordPress to display the top parent page title rather than the current page’s title as the heading on the page. Here’s the code we used to accomplish that:

<?
$currPost = $post;
while ($currPost->post_parent) {
  $currPost = $currPost->post_parent;
}
$title = get_the_title($currPost);
?>

<h2>[ <?php echo $title; ?> ]</h2>

No Comments »

No comments yet.

RSS feed for comments on this post. TrackBack URL

Leave a comment




Enter the code to the right