Support » Fixing WordPress » Category Title Tag

  • In the sidebar of all my pages, I have a <?php the_title() ?> tag that puts the title of the page at the top of sidebar. However, on the category archive pages that display a list of posts in that category, I get the title of the first post there, instead of the category title.

    Is there a template tag or another way to display the title of the category archive I’m viewing?


Viewing 5 replies - 1 through 5 (of 5 total)
  • Thanks, that will be useful.

    Sorry if I worded it wrong, but I need code that will check to see if the current page is a category archive, and if it is, display the category title. Otherwise, it should just display the page title.

    Category archives are NOT Pages – so cannot have titles.
    For category archives WP has the Category_Templates.

    A good example of displaying the category title/name is in the archive.php of the Default theme.
    Note, it is using that template file to display category archives… according to the Template_Hierarchy.
    [oops link fixed by MH 😉 ]
    Seemingly, you started in the wrong way by using Pages to display posts. That’s the hard way. How WP works, that’s the easy way. You pick…

    i got this <h1><?php single_cat_title(''); ?></h1>
    on my page.
    How to combine it with <h1><?php single_tag_title(''); ?></h1>?
    so the “currently browsing <h1>” is
    flexible between those 2 tags.
    My guess is using “if else condition” but I don’t know how to write these.. 🙁
    please help..

    never mind the updated kubric template solve it for me 😀

    <?php $post = $posts[0]; // Hack. Set $post so that the_date() works. ?>
    <?php /* If this is a category archive */ if (is_category()) { ?>
    <h1><?php single_cat_title(); ?></h1>
    <?php /* If this is a tag archive */ } elseif( is_tag() ) { ?>
    <h1><?php single_tag_title(); ?></h1>
    <?php /* If this is a daily archive */ } elseif (is_day()) { ?>
    <h1>Archive for <?php the_time('F jS, Y'); ?></h1>
    <?php /* If this is a monthly archive */ } elseif (is_month()) { ?>
    <h1>Archive for <?php the_time('F, Y'); ?></h1>
    <?php /* If this is a yearly archive */ } elseif (is_year()) { ?>
    <h1>Archive for <?php the_time('Y'); ?></h1>
    <?php /* If this is a paged archive */ } elseif (isset($_GET['paged']) && !empty($_GET['paged'])) { ?>
    <?php } ?>
Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Category Title Tag’ is closed to new replies.