How To Add Category Thumbnails To Homepage In WordPress

I had to come up with the task of creating category thumbnails for a friend of mine. Here is a snippet of code if you need to use this:


global $post;
$temp_post = $post;
$args = array(‘numberposts’ => 6, ‘category’ => 227, ‘orderby’ => ‘date’, ‘order’ => ‘DESC’);
echo ‘<div class=”categoryThumbnailList”>’;
$myposts = get_posts($args);
foreach ($myposts as $post) : setup_postdata($post);
if (has_post_thumbnail()) {
$thumbnail = get_the_post_thumbnail($post->ID, ‘thumbnail’);
$link = get_permalink($post->ID);
$title = get_the_title();
echo ‘<div class=”categoryThumbnailList_item”>’;
echo ‘<a href=”‘ .$link . ‘” title=”‘ .$title . ‘”>’ .$thumbnail . ‘</a><br/>’;
echo ‘<a href=”‘ .$link . ‘” title=”‘ .$title . ‘”>’ .$title . ‘</a>’;
echo ‘</div>’;
echo ‘</div>’;
echo ‘<div class=”categoryThumbnailList_clearer”></div>’;
$post = $temp_post;


Leave a Comment

Your email address will not be published. Required fields are marked *