WordPress.org

Support

Support » How-To and Troubleshooting » Duplicate listing of post under category

Duplicate listing of post under category

  • I wrote a bit of code that prints all post under a category and displaying the feature image of that post.

    However I’m not sure what’s wrong with my loop as it’s printing the same post X number of times. X being the number of categories I have.

    Here is my code…

    <?php
    	$cats = get_categories();
    	$thumbnails = get_posts();
    	foreach ($cats as $cat) {
    	    $cat_id = $cat->term_id;
    	    if ( has_post_thumbnail($thumbnail->ID, $category->term_id)) {
    		      echo '<li><a href="' . get_permalink( $thumbnail->ID ) . '" title="' . esc_attr( $thumbnail->post_title ) . '">';
    		      echo get_the_post_thumbnail($thumbnail->ID, 'full');
    		      echo '</a></li>';
    	    }
    	}
    ?>

Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Duplicate listing of post under category’ is closed to new replies.
Skip to toolbar