WordPress Category Titles ­ Articles ­ the bombsite

. . . .

Subscribe

Statistics

Article Comments
Categories
Famous Articles

Sign Up for Email Updates

Want to Send Me Something?

Need Some Icons?

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?

Editas 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 )

  • 1
    Thomasso Aug 17, 05:00 AM
    Yup, I'm finding a whole pile of stuff too. I was looking through Kitten's and Nuk-Moose's weBlogs, they got a many nifty little things you can do too. I added some plguins and changed some php code in the index.php file yesterday. See if you can findout what got changed... :dance:

    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:
  • 2
    Thomasso\'s weblog Aug 17, 06:45 AM
    Getting the RSS feed thingy figured out!
    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....
  • 3
    Stuart Aug 17, 04:21 PM
    Well that seems to have worked Tom. :clap: I'll have to come over and see if I can spot your changes. I'm just so busy at the moment I'm really not doing too much surfing. :boohoo: I keep Kitten's devblog on my feed reader so I can catch the new stuff. I've only really glanced through Moose's site. Must spend a bit more time on it. :doh:
  • 4
    Shadow Aug 18, 10:24 PM
    Hi Stuart,

    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:
  • 5
    Stuart Aug 19, 02:25 AM
    _Email reply sent_.
  • 6
    Shadow Aug 19, 02:46 AM
    Thanks for all your help Stuart.

    I have it running on my site now nd it is just what I was after...

    Thanks again for sharing :clap: :notworthy:
  • 7
    Stuart Aug 19, 04:46 AM
    Nema problema. It's Janne you should thank though. It's his _eagle-eye_ that spotted it.
  • 8
    wordlog.com » Displaying Titles on Category Pages Aug 20, 10:58 AM
    [...] @ 12:58 am


    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
  • 9
    Kunjan Aug 20, 01:42 PM
    This is great work!

    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
  • 10
    doug Aug 20, 01:46 PM
    what about displaying the 'month, year' as a page title on the monthly archive pages?
  • 11
    doug Aug 20, 01:49 PM
    ah, i see this is moot for those who have adopted the 'nicer archives' plugin.

    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.
  • 12
    pinkasphalt Aug 20, 03:42 PM
    Categoray Titles
    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...
  • 13
    Stuart Aug 20, 09:36 PM
    Thanks to everyone for the links.
    @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.
  • 14
    kpont.com Aug 21, 04:45 AM
    Showing category titles in WordPress
    Stuart at the bomb site weblogshows us how to make category titled show up in WordPress.

    Hat tip: Wordblog

Commenting is closed for this article.

 
BACK TO THE TOP
Need A Textpattern Expert?
Do you have an existing theme that you really like but it is designed for some other application?
Maybe you are a designer but lack the coding skills to turn your design into a working web site?
Maybe you are completely new to the world of web sites?

Then what you need is ME!

Get in touch for a quote