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:-
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:-
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.