Forums

[resolved] Only show post thumbnails - for one category (5 posts)

  1. tjobbe
    Member
    Posted 1 year ago #

    I'd like to show all the post-thumbnails from a specific blog category in my sites footer.

    What this will mean is that there will be nine thumbnails, each from the latest post in a specific category (in this case "work"), and they will display in my footer in a 3 by 3 grid layout, each linking through to the relevant blog post.

    I have the thumbnails working, but not sure how to call ONLY the thumbnail andurl to the post, for a specific category, and limit it to the last 9 posts!

    Can any please help me?

  2. alchymyth
    The Sweeper
    Posted 1 year ago #

    http://codex.wordpress.org/Template_Tags/get_posts
    http://codex.wordpress.org/Function_Reference/get_permalink
    http://codex.wordpress.org/Function_Reference/get_the_post_thumbnail

    for instance (example without html tags for formatting):

    <?php
    $footer_thumbs = get_posts('category_name=work&numberposts=9');
    if( $footer_thumbs ) :
      foreach( $footer_thumbs as $footer_thumb ) {
      setup_postdata($footer_thumb);
      echo 'a href="' . get_permalink($footer_thumb->ID) . '"> . get_the_post_thumbnail($footer_thumb->ID) . '</a>';
      }
    endif;
    ?>

    untested

  3. tjobbe
    Member
    Posted 1 year ago #

    Thank you so much for this, looks like what I need! However, when I plug this into index.php I get the following:

    Parse error: syntax error, unexpected '/' in C:\xampp\htdocs\sites\pla2011\wp-content\themes\starkers\index.php on line 30

    and line 30 being:

    echo 'a href="' . get_permalink($footer_thumb->ID) . '"> . get_the_post_thumbnail($footer_thumb->ID) . '</a>';

    Looks like a syntax error, but I can't spot it?

  4. alchymyth
    The Sweeper
    Posted 1 year ago #

    my mistake, a missed ' :

    should be:

    echo 'a href="' . get_permalink($footer_thumb->ID) . '">' . get_the_post_thumbnail($footer_thumb->ID) . '</a>';

  5. tjobbe
    Member
    Posted 1 year ago #

    Perfect, thank you so much!

Topic Closed

This topic has been closed to new replies.

About this Topic