Post thumbnails with different colors based on category?
-
I’m really new to coding with wordpress/PHP and I’m struggling to figure out how implement different styles for thumbnails depending on their category.
Right now I’m making a news website with 4 categories (news, sports, entertainment, columns) and each category has a different color associated with it. I’d like for the thumbnails and excerpts to display the color of the category it’s in. I’m trying to insert the post category into a class which I can then style, but I just get a bunch of one random category listed as links at the top of my grid instead of my thumbnails getting an actual class/id. This is the current code for my thumbnails:
<?php $thumbnails = get_posts('numberposts=6'); foreach ($thumbnails as $thumbnail) { if ( has_post_thumbnail($thumbnail->ID)) { echo '<div class="small_feature"><a href="' . get_permalink( $thumbnail->ID ) . '" title="' . esc_attr( $thumbnail->post_title ) . '"><div class="colored_bar' . the_category( ' ' ) . '"></div>'; echo get_the_post_thumbnail($thumbnail->ID, 'thumbnail'); echo '<div class="overlay_bar"> <h2 class="post_title_thumbnail"> ' . esc_attr( $thumbnail->post_title ) . '</h2></div></a></div>'; } } ?>
Which results in this, links to one random category and no id or class in the actual colored bar:
LinkThis is what I want, each side colored bar is a different color corresponding to its category:
LinkThanks, any help would be appreciated!
- The topic ‘Post thumbnails with different colors based on category?’ is closed to new replies.