WordPress.org

Forums

[resolved] get date from latest post of category (4 posts)

  1. bjonesilg
    Member
    Posted 2 years ago #

    Hi, I'm writing some code where a container will either show a panel or another based on the argument of if date from latest post of category is greater than date from latest post of another category then show this, else show this. How can I get the published date from the latest post of a category? Furthermore is the argument of greater than for date the right argument to use?

  2. riversatile
    Member
    Posted 2 years ago #

  3. alchymyth
    Forum Moderator
    Posted 2 years ago #

    http://codex.wordpress.org/Template_Tags/get_posts
    http://codex.wordpress.org/Function_Reference/get_the_time
    http://uk3.php.net/manual/en/function.date.php

    example (for category 17 vs category 29):

    <?php
    $cat1_posts = get_posts('posts_per_page=1&category=17');
    $date1 = get_the_time('U',$cat1_posts[0]->ID);
    $cat2_posts = get_posts('posts_per_page=1&category=29');
    $date2 = get_the_time('U',$cat2_posts[0]->ID);
    if( $date1 > $date2 ) : ?>
    do whatever
    <?php else : ?>
    do whatever otherwise
    <?php endif; ?>
  4. bjonesilg
    Member
    Posted 2 years ago #

    absolutely perfect! worked like a charm, thanks alchymyth!

Topic Closed

This topic has been closed to new replies.

About this Topic