Wordpress question.

Discussion in 'WordPress' started by huntz, Nov 12, 2008.

  1. #1
    Hey guys got a Wordpress question. I'd be grateful for some help.

    Hello,

    I have a function i run on my single.php at the bottom of the page like so.

    <?php echo display_message() ?>

    I dont want to run the function if its on the most recent post.

    I've had a go myself with

    $getlatestpost = get_posts('numberposts=1&order=DESC&orderby=post_date');
    $latestpostid = $getlatestpost ->ID;

    If $post->ID == $latestpostid;
    echo display_message();
    else;
    /* do nothing */
    endif;

    but its not working, can anyone help?
     
    huntz, Nov 12, 2008 IP
  2. Ikki

    Ikki Peon

    Messages:
    474
    Likes Received:
    34
    Best Answers:
    0
    Trophy Points:
    0
  3. huntz

    huntz Well-Known Member

    Messages:
    699
    Likes Received:
    110
    Best Answers:
    0
    Trophy Points:
    133
    #3
    Hey, i've had a look there, i don't think it explains how to get the id using get_post to get the latest post.

    If i could compare the latest post number with the current post tha'd be fine.
     
    huntz, Nov 12, 2008 IP
  4. Ikki

    Ikki Peon

    Messages:
    474
    Likes Received:
    34
    Best Answers:
    0
    Trophy Points:
    0
    #4
    It does.

    You can get the current post's ID with $post->ID. Once you do that, compare it with the latest post's ID with $post->ID ORDER BY post_date ASC LIMIT 1. If they don't match, it means that the current post isn't the latest one.
     
    Ikki, Nov 13, 2008 IP