WordPress Category Titles
There are a few “functions” that already exist in WordPress which can be put to good use if you know about them. I found out about this one and started using it about a week or so ago but just haven’t had time to write it up as I’ve been busy on other things. This particular one may be useful for people from a “presentational” point of view.
It would appear that when you select a category (from the list in my menu) there is a “function” that can show the category title. As it already exists there is no “hacking” involved at all. You just need to place a call to the function wherever you want it to appear on your page then give the call it’s own div so you can style it in your CSS. If you want to see what I mean just select a category. Now I don’t want to pressure you but if you select the “WordPress” category you will still have this post in front of you. See the nice “WordPress” title at the top? Wasn’t there before was it?
Edit – as I no longer use WordPress I’m afraid you won’t be able to see this in action. Just take my word for it that it works.
So here’s how you do it. This is the function as it already exists:-
get_the_category_by_ID()
So if you use an “if” statement to determine whether a category has been selected or not and an “echo” to print it’s name to screen, you can place a call in your index.php file which will only show when someone has selected a category. So you end up with this:-
if(isset($cat)) {
echo get_the_category_by_ID($cat);
}
Now remember that this is PHP so you need to surround it with the opening and closing PHP tags (or put it inside existing PHP tags though this may make styling difficult) and then surround the whole thing with “div” tags. I happen to have called my “id” “category” which seemed logical at the time. You can call it what you want then you can style the “id” to your hearts content in your CSS. Simple really!
My thanks to Janne at Nomadig for pointing this one out.








Comments ( 14 )
Also, I saw for the first time your RSS link on your freinds "janne's" site. I'm going to RSS one of your posts just to see what heppens? :think:
This is just another test to get the RSS Feed going. I was over at Stuart's weBlog and notice that he was using the RSS / Track Back /ping on one of his friend's website. So here it goes. This is a RSS feed from Stuart's page on his last Blog entry....
Sorry to ask - I realise you are busy - but could you spell this procedure out in 'dummy' terms. I cannot find reference to
`get_the_category_by_ID()` in my index and not sure where
`if(isset($cat)) {
echo get_the_category_by_ID($cat);
}` is actually placed.
Thanks for any advice you can offer :oops:
I have it running on my site now nd it is just what I was after...
Thanks again for sharing :clap: :notworthy:
Stuart again. This time, he writes a neat little tutorial to explain how to display the name of the category as the title on category pages. He writes : There are a few
I had problems with the run over menu on my site too.
But since I have a custom CSS... So can you point out what was the problem with the run-over menu and how to fix it?
That would be great.
Thanks
in my case, the blog does not utilize categories or multiple authors, and i need the excerpt displayed, so this kind of archive is not a great match.
I found a great tip over at The Bombsite that does something that I had been wanting to do. It allows you to display the category title on a category archive page. So if you click on the Wordpress category link at the end of this post, the next page w...
@Doug - you spotted the "nicer archives" then. I'll have a look at your problem when I have time. I'm a tad busy just now. I'll let you know if I find anything.
@Kunjan - I see you use a "fixed-width" layout. I'm doing a piece on the principals of this "fix" but my expertise (if you want to call it that) is with the fluid-type design. The principals are the same but I think the application is slightly different. You could take a look at Root's "Gemini Interface" and compare how the extra divs and related CSS apply to your site.
Stuart at the bomb site weblogshows us how to make category titled show up in WordPress.
Hat tip: Wordblog