Forums

Show date only on certain posts (4 posts)

  1. wjnesbitt
    Member
    Posted 2 years ago #

    Currently, my blog is divided into two sections - blogs and articles. The blogs are material that I write and the articles are material from other authors.

    I would like to set it up so that the date only shows up in the blogs and not the articles. How can I achieve this?

    Thanks.

  2. MichaelH
    Volunteer
    Posted 2 years ago #

    The Loop article discusses using a conditional tag to exclude categories, so you could use the same technique:

    <?php if (in_category('blogs')) {
    the_time('F jS, Y');
    ?>

    Related:
    the_time()
    Stepping Into Template Tags
    Stepping Into Templates
    Template Hierarchy

  3. ryans149
    Member
    Posted 2 years ago #

    remove the date tags from archive.php and index.php

    http://codex.wordpress.org/Template:Date_Tags

  4. DeirdreBunny
    Member
    Posted 2 years ago #

    For other people looking for info on this, Michael H. had it right, but I had to remove his "{" otherwise it was invalid and creating a syntax error.

    I removed the original date tag beneath title in the index and replaced it with:

    <?php if (in_category('blogs')) the_date('','<h2>','</h2>'); ?>

    Then I created a category called 'blogs' and made sure all of my posts had that category checked.

    Now, if all goes well, only items in the category 'blogs' will show post dates. You just have to remember to tick of that cat every time you make a new post (along with whatever other categories you want to tick off).

    There are other methods to do this when there is a page.php file, but if there isn't try the above method -- I often start my custom themes from the classic theme, and the classic theme doesn't include a page.php.

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags