If you are like me, you probably want your website to have excellent navigation, and let people know where they are on your website pretty much all the time.
SO I WAS LOOKING FOR A WAY TO DISPLAY SOME INFORMATION LIKE CATEGORY NAME IN WORDPRESS (to be a header for an ordered list of that category’s other posts.) That topic will be covered later by the way.
So I made it happen, but then my Word Press pages were showing the header for the category ‘uncategorized’ (Not cool!)
Here’s a good way to show the header on all pages except your main web pages.
global $post;
$category = get_the_category();
if ( is_page() ) {
}
else{
echo 'Posting Filed in ' .$category[0]->cat_name;
}
?>
***UPDATE***
The above code works great, but unfortunately I just noticed that it still shows up even if there are no posts in that category. That’s fine because I am using that page as an index page, and there aren’t supposed to be ‘POSTS’ in that category, however just having a header hanging out there is kind of stupid (that’s what I’m using this code for, a header in a widgetized sidebar)
Use this PHP instead…
global $post;
$category = get_the_category();
if ( is_page() ) {
}
else{
if ( have_posts() ) {
echo $category[0]->cat_name;
}
}
?>
Popularity: 5% [?]
Comments
Leave a comment Trackback