WordPress.org

Ready to get started?Download WordPress

Forums

Category Title Tag (6 posts)

  1. ethayne
    Member
    Posted 6 years ago #

    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?

    Thanks!

  2. MichaelH
    Member
    Posted 6 years ago #

  3. ethayne
    Member
    Posted 6 years ago #

    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.

  4. moshu
    Member
    Posted 6 years ago #

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

  5. coroijo
    Member
    Posted 6 years ago #

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

  6. coroijo
    Member
    Posted 6 years ago #

    never mind the updated kubric template solve it for me :D

    <?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'])) { ?>
    <h1>Archives</h1>
    <?php } ?>

Topic Closed

This topic has been closed to new replies.

About this Topic