Solution: Add Category Featured Images
-
I’ve done a lot of searching for this and I’ve tried category templates,w which oddly do not work. Category templates are purposefully overridden in this theme…? (Category-id, etc)… I’m not a programmer but I can tinker some so here’s my solution (which so far has worked perfectly) to add category featured images with post excerpts. FOR CATEGORIES. NOT INDIVIDUAL POSTS.
Ascetica natively supports gallery post type thumbnails. Not for regular posts on category archives. To add that support, do this…
- First activate the child theme if you are not using it already.
- Move archive.php into the child theme folder.
- Open content-gallery.php from the parent theme folder.
- Copy the following code for featured thumbnails:
<?php if ( current_theme_supports( 'get-the-image' ) ) get_the_image( array( 'meta_key' => 'Thumbnail', 'size' => 'singular-gallery-thumbnail', 'link_to_post' => false, 'image_class' => 'featured', 'default_image' => get_template_directory_uri() . '/images/singular_gallery_thumbnail_placeholder.png', 'width' => 400, 'height' => 230 ) ); ?>
- Paste the code in archive.php in your child theme where you want the featured image per post to show up. I paste mine after the title, but before the excerpt. Like this:
<?php echo apply_atomic_shortcode( 'entry_title', '[entry-title]' ); ?>
<?php if ( current_theme_supports( 'get-the-image' ) ) get_the_image( array( 'meta_key' => 'Thumbnail', 'size' => 'singular-gallery-thumbnail', 'link_to_post' => false, 'image_class' => 'featured', 'default_image' => get_template_directory_uri() . '/images/singular_gallery_thumbnail_placeholder.png', 'width' => 200, 'height' => 150 ) ); ?>
- Save, close, upload archive.php over the current one.
- Now go to style.css in the child theme. Paste this CSS (same CSS as applied for gallery featured images):
.singular-gallery-thumbnail { float: left; width: 60.60606060606061%; margin:0 30px 30px 0; }
@media only screen and (max-width: 767px) {
.singular-gallery-thumbnail { width: 100%; float:none;}
}The @media version is responsive for smart phone screens.
- Save, close, upload style.css over the current one in the child theme.
The featured images should now work correctly in your site. And since the featured images apply a conditional PHP statement for if they exist, there won’t be odd gaps on any posts that may not have an attributed featured image.
- The topic ‘Solution: Add Category Featured Images’ is closed to new replies.