WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] get latest post from a single category display linking thumbnail (3 posts)

  1. sullyde
    Member
    Posted 1 year ago #

    Hi all
    I have been using the code below to display the featured image of the latest post from the specified category. But it has stopped working, any ideas or better code?
    Site is here the white box next to the slider is where the thumbnail used to appear.

    <?php
    query_posts('cat=75');
    if ( has_post_thumbnail()) {
      echo '<a href="' . get_permalink() . '" >' . the_post_thumbnail() .'</a>';
    }
    ?>

    Many thanks in advance

  2. alchymyth
    The Sweeper & Moderator
    Posted 1 year ago #

    try:

    <?php
    $cat75 = get_posts('cat=75&posts_per_page=1');
    if ( has_post_thumbnail($cat75[0]->ID)) {
      echo '<a href="' . get_permalink($cat75[0]->ID) . '" >' . get_the_post_thumbnail($cat75[0]->ID) .'</a>';
    }
    ?>

    http://codex.wordpress.org/Template_Tags/get_posts
    (untested)

  3. sullyde
    Member
    Posted 1 year ago #

    Thank you for a very fast response, that has worked perfectly.

    Many thanks

Topic Closed

This topic has been closed to new replies.

About this Topic