Forums

Display something based on the publication date and cat (3 posts)

  1. planetphillip
    Member
    Posted 1 year ago #

    Hi,

    I would like to be able to display some text based on whether the post is older than 2008 and in a certain category. I know how to display something if it's in a certain cat. but can't find a way to
    A display if it's before a certain date and
    B combine the two.

    I know there is the "is_date conditional but that seems to be used for archive pages and I would like this to be used on single pages.

    Any help gratefully received.

    My level of coding is basically "cut and past".

    TIA

  2. alchymyth
    The Sweeper
    Posted 1 year ago #

    <?php if( in_category('certaincat') && (get_the_time('Y') > 2008) ) { /*show text*/ } ?>

    get_the_time():
    http://codex.wordpress.org/Function_Reference/get_the_time

    formatting date:
    http://php.net/manual/en/function.date.php

  3. planetphillip
    Member
    Posted 1 year ago #

    Thank you for your reply and help.

    I kept getting a parse error with your code but a little copying and pasting from something else got me this

    <?php
    if ( in_category('catnamehere') && (get_the_time('Y') < 2008) ) {
    echo 'text here';
    } else {
    echo '';
    };
    ?>

    There's probably a more elegant way of doing it but it works.

    Thanks again, your reply made all the difference.

Topic Closed

This topic has been closed to new replies.

About this Topic