I was looking around google and here but nothing found about this.
<div class="thumbBlock">
<?php foreach (get_categories() as $cat) : ?>
<div class="thumbInside">
<a href="<?php echo get_category_link($cat->term_id); ?>" title="<?php echo $cat->name; ?>" />
<img src="POST_THUMBNAIL HERE FOR EACH CATEGORY" alt="<?php echo $cat->name; ?>" />
</a>
<p><a href="<?php echo get_category_link($cat->term_id); ?>" title="<?php the_title(); ?>"><?php echo $cat->cat_name; ?></a></p>
</div>
<?php endforeach; ?>
</div>
as u see I want to list categories in a custom template but in the place post thumbnail I want to grab last post thumb for each category is it possible?
I think you'll find the_terms and get_the_terms to be better functions
$terms = get_terms( 'my_taxonomy' );
if ( ! empty( $terms ) && ! is_wp_error( $terms ) ){
echo '<ul>';
foreach ( $terms as $term ) {
echo '<li>' . $term->name . '</li>';
/* use the term id to find matching posts in this taxonomy */
$args = array (
'showposts' => 1,
'orderby' => 'date',
'order' => 'DESC',
'tax_query' => array(
array(
'taxonomy' => 'my_taxonomy',
'field' => 'term_id',
'terms' => $term->term_id,
),
),
);
$new_query = new WP_Query( $args );
if ( $new_query->have_posts() ) {
while ( $new_query->have_posts() ) {
$new_query->the_post();
$post_id = get_the_ID();
echo '<li>';
echo get_the_post_thumbnail( $post_id, 'thumbnail' );
echo '</li>';
} // end while
} else {
// no posts found
}
/* Restore original Post Data */
wp_reset_postdata();
}
echo '</ul>';
}
This hasn't been tested, but should get ya pretty close.