So I'm working on a site and I need a news page that is slightly different. It is a post category but I want the text echoed at the top of the news category listing.

<?php endif; ?>
<?php /* If this is a category archive */ if (is_category()) { ?>               
    <h2>Board: <?php echo single_cat_title(); ?></h2>
<?php /* If this is a daily archive */ } elseif (is_category('news')) { ?>
    <h2>News: </h2>
<?php /* If this is a daily archive */ } elseif (is_day()) { ?>
    <h2>Daily Archive | Board: <?php the_time('F jS, Y'); ?></h2>
<?php /* If this is a monthly archive */ } elseif (is_month()) { ?>
    <h2>Monthly Archive | Board: <?php the_time('F, Y'); ?></h2>
<?php /* If this is a yearly archive */ } elseif (is_year()) { ?>
    <h2>Yearly Archive | Board: <?php the_time('Y'); ?></h2>
<?php /* If this is a search */ } elseif (is_search()) { ?>
    <h2>Search Results: </h2>
<?php /* If this is an author archive */ } elseif (is_author()) { ?>
    <h2>Author Archive: </h2>
<?php /* If this is a paged archive */ } elseif (isset($_GET['paged']) && !empty($_GET['paged'])) { ?>
    <h2>Archives: </h2>
<?php } ?>

This code works fine for archives except the fact that <?php /* If this is a daily archive */ } elseif (is_category('news')) { ?> <h2>News: </h2> does not work when you view the news category. It shows the standard text for every other category.

Then if you do <?php if (is_category('News')) : ?> <p>News:</p> <?php else : ?> it works and shows that text when viewing the news category. How do I get it to work so that when you view the news category it shows one specific set of text at the top of the page? Because the methods I have tried do not seem to be working.


The easiest way to do it is to use a category template and let WordPress step through its template hierarchy and display the News template when it is called.

So you would copy your theme's category.php to category-news.php (assuming the slug is "news") and then edit that file to place whatever text you want where ever you want it.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.