Selecting the most recent post for special treatment (8 posts)

  1. pschena
    Posted 6 years ago #

    Looking to hack the code of single.php so that I can add a link to the next story.
    We currently use the nav-above/nav-below links in Sandbox to get from one story to the next. The client would like to have the first story link with different text from the headline.

    Need to isolate the latest post and have a link like "Check out more news…"
    Would like to leave all other posts as they currently are.
    Site in question is: http://showfx.com.au/news/

    Thanks in advance

  2. pschena
    Posted 6 years ago #

    For the more code savvy users, would it be possible to count the number of posts and return that variable for use in an IF statement?

    Something like:

    $MostRecent = HowManyPostsAreThere
    if (is_post('$MostRecent')) echo (blah blah)
    (do nothing)

    Would something like this work or be possible?
    Not sure of the actual code involved.
    Any help?

  3. pschena
    Posted 6 years ago #

    No that won't work.
    No relationship between number of posts and the postID apparently.
    Keep trying.

  4. pschena
    Posted 6 years ago #

    So on further research
    <?php $newest_post_id = $posts[0]->ID; ?>
    does the job of identifying the most recent post.

    With this pearl, can someone tell why this would not work.

    <?php $newest_post_id = $posts[0]->ID; ?>
    <?php if(the_ID == $newest_post_id) {
    echo 'yes';
    } else {
    echo 'no';
  5. Chris_K
    Posted 6 years ago #

    Check this reply: http://wordpress.org/support/topic/171547?replies=4#post-742974

    Would that work for you?

  6. pschena
    Posted 6 years ago #

    hmmm, not sure that it does.
    I am trying to modify single.php and that example looks like it would work for the list of posts in my limited experience.

    Thanks though!

  7. Chris_K
    Posted 6 years ago #

    apologies - I skimmed your OP and totally missed the point! :-\

  8. Toby Cryns
    Posted 5 years ago #

    Did you find a solution to this problem?

Topic Closed

This topic has been closed to new replies.

About this Topic