Community Forums › Forums › Archived Forums › Design Tips and Tricks › Featured Image for Post Categories
- This topic has 6 replies, 2 voices, and was last updated 11 years ago by Anita.
-
AuthorPosts
-
April 18, 2013 at 11:05 am #36164AnitaKeymaster
I have 5 Post Categories. For each category my client wants to be able to update the featured image to showcase that month's charts or graphs as it pertains to that category's blog entries. First I thought to create individual pages which would allow me to use the Featured Image and use the SEO to forward that page to the Category page - but that wouldn't work.
So... does anyone have any idea how I can do this? Thank you much.
Love coffee, chocolate and my Bella!
April 18, 2013 at 1:46 pm #36206David ChuParticipantHi,
Yes. 🙂 I like your idea. Following your scheme, I wrote some code to that effect. As you can see, it checks for the category, and if it's in that category, you grab the Featured Image from a particular page, whose number can be found by hovering over the title in the admin (235 in this example). I used a Post for testing, but a Page should work equally well. You could just repeat that code block to correspond to other Categories and other Page/Posts.Then the client or you could just change the Featured Image on those particular Pages to freshen things up.
Some styling possibly needed, obviously. One could also add some more HTML to have a nice DIV for it or what-have-you. And of course, other hooks could be used besides genesis_before_loop.
add_action('genesis_before_loop', 'dc_put_in_featured'); function dc_put_in_featured() { if ( is_category( 'Category #1' ) ) { echo get_the_post_thumbnail(235, 'full'); } }
Cheers, Dave
Dave Chu · Custom WordPress Developer – likes collaborating with Designers
April 18, 2013 at 2:03 pm #36207AnitaKeymasterThank you David. So if I have 5 categories - just add the action 5 separate times, i.e., Category 1, Category 2, etc., etc., with their specific page ids?
Love coffee, chocolate and my Bella!
April 18, 2013 at 2:30 pm #36214David ChuParticipantYW!
You could do that. But it's cleaner to just repeat this inner block inside the function, and change the code for each Category and Post. Here's a quick example:add_action('genesis_before_loop', 'dc_put_in_featured'); function dc_put_in_featured() { if ( is_category( 'Category #1' ) ) { echo get_the_post_thumbnail(235, 'full'); } if ( is_category( 'Category #2' ) ) { echo get_the_post_thumbnail(123, 'full'); } }
Dave Chu · Custom WordPress Developer – likes collaborating with Designers
April 18, 2013 at 2:40 pm #36218AnitaKeymasterBeautiful! It works B-E-A-U-T-F-U-L!!! Thank you!
Love coffee, chocolate and my Bella!
April 18, 2013 at 2:54 pm #36221David ChuParticipantNice!!
One could also do this via Custom Fields, too. There are frequently many ways to do a particular task.Dave
Dave Chu · Custom WordPress Developer – likes collaborating with Designers
April 18, 2013 at 2:58 pm #36222AnitaKeymasterI think for my client - the way you coded it will be the easiest way to explain it to him. Very straight forward.
Love coffee, chocolate and my Bella!
-
AuthorPosts
- The topic ‘Featured Image for Post Categories’ is closed to new replies.