Forums

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

  1. sullyde
    Member
    Posted 8 months 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 8 months 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 8 months ago #

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

    Many thanks

Reply

You must log in to post.

About this Topic