Support » Fixing WordPress » category in title on post pages

  • I am using 1.5 (will upgrade to 1.5.1 later today–yippee!) and would like to have the category name displayed in the title tag of my site. I have this in the header.php file:

    <?php the_category(', ') ?>

    and this displays the category name with no issues on the home page of the site and on the category pages. It does not however show the correct category name on individual post pages. Instead, “Uncategorized” is always displayed. The posts are NOT assigned to the Uncategorized category.

    How can I have my proper category names displayed on post pages?

    All comments appreciated.

    TIA!!
    JF 😉

Viewing 8 replies - 1 through 8 (of 8 total)
  • Do you have a link to your site so we can see what is happening.

    And, are you using a Theme that showcases your single posts on a different template like single.php or post.php? If so, then check there to see that you have the identical title layout there as you do on the index.php template file. That might be your problem, though the uncategorized issue is something else. Check this part first.

    Thread Starter jfriesen

    (@jfriesen)

    Hi Lorelle–

    Thank you for your reply!

    I am using a bastardization of Almost Spring and Gila:

    http://www.ppcprimer.com/

    There is a single.php file… it begins with

    <?php get_header(); ?>

    so I assume there is no need to replicate the actual code from header.php in that file?

    Here is the complete title tag code from header.php:

    <title><?php bloginfo('name'); if ( is_home() ) { ?> &raquo; <?php bloginfo('description'); } if ( is_single() ) { ?> &raquo; <?php the_category(', ') ?> <?php } wp_title(); ?></title>

    As I mentioned, everything works fine until you go to a single post page:

    http://www.ppcprimer.com/?p=10

    which is when “Uncategorized” rears its pointed little head.

    thanks!
    JF 😉

    the_category() is only valid from within The Loop. You’ll have to initiate your Loop in your header, then reset it. Something like:

    if ( is_single() ) { the_post(); ?> &raquo; <?php the_category(', '); ?> <?php rewind_posts(); } wp_title(); ?>

    Thread Starter jfriesen

    (@jfriesen)

    Thanks for the tip! I have to read more about the Loop.

    The code you suggested works almost perfectly. The only flaw is that it prints anchor tags to the title:

    <title>PPC primer &raquo; <a href="http://www.ppcprimer.com/?cat=2" title="View all posts in Get Primed!" rel="category tag">Get Primed!</a> &raquo; 10 Tips for Maximizing Your Campaigns</title>

    How can this be worked around?

    JF 😉

    True. There’s apparently no function to just print names of categories. You’ll need to create a function, perhaps in a plugin.

    Thread Starter jfriesen

    (@jfriesen)

    OK, thanks! Plugin development is a little too much for this WP newbie right now, but it’s a great idea since it would provide a handy search engine optimization feature to WP. Perhaps someone out there will… bite!

    cheers
    JF 😉

    I have a similar problem, I am trying to display the categories above the posts, but for some reason I am getting some very strange formatting behavior that I can’t find the source of.

    My site is mochasteak.com/blog, and I am not using a separate ‘post.php’ page. I have a “the_category” function getting the link, and I have it in its own div, and have two separate styels for normal and hover states, but for some reason the silly boy always comes out underlined.

    UNDERLINED!

    THat’s not even the way it looks in the example on the Codex and I certainly didn’t tell it to do that and it simply won’t listen to reason. “style=”text-decoration:none;” doesn’t do a thing.

    Help!

    Hi JF,

    Just checked out your site based on Almost Spring and Gila for http://www.ppcprimer.com/.

    Wow, that is one great looking site.
    Any chance at all that you could sent me a copy of it or make it available? I know you have probably put a lot of work into it so understand if not.

    Good luck with the site.

    Bob
    contact at bobharrison dot net

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘category in title on post pages’ is closed to new replies.