Home › Forums › Pro Support › Show categories inside featured images
- This topic has 15 replies, 4 voices, and was last updated 2 years, 3 months ago by
elvin.
-
AuthorPosts
-
September 17, 2020 at 10:36 pm #19532
Liran
ParticipantHey,
With the help of the support team at GeneratePress, I was able to get the categories to show inside the featured images (here’s an example).
Any idea of how to make this work with WPSP as well?
September 18, 2020 at 1:31 pm #19581Tom
KeymasterHi there,
Can you share the code you’re using for the GP posts? It should be very similar, we just need to add the items to the
wpsp_inside_image_container
hook.September 18, 2020 at 1:45 pm #19591Liran
ParticipantHere it is:
.post-image{ position: relative; } .post-image > a > img.wp-post-image { width: 100%; } .post-image > span.cat_links { position: absolute; margin:0; top:auto; bottom: 7.5%; left: 5%; } .post-image > span.cat_links > span > ul{ list-style:none; margin:0; padding:5px; }
September 18, 2020 at 2:37 pm #19597elvin
ModeratorHi Liran,
I’ve rewritten the code to work for WPSP. You can try this PHP code out.
add_action( 'wpsp_inside_image_container', function( $settings ) { if ( 77 === $settings['list_id'] ) { $wpsp_cat_list = get_the_category_list(); $wpsp_category = get_the_category(); if ($wpsp_category) { foreach($wpsp_category as $wpsp_cat) { $wpsp_cat_slug = $wpsp_cat->slug; } } if($wpsp_cat_list){echo '<span class="cat_links"><span class="'.$wpsp_cat_slug.'">'.$wpsp_cat_list.'</span></span>';} } });
And style it with this CSS code.
.wp-show-posts-image{ position: relative; } .wp-show-posts-image > a > img.wp-post-image { width: 100%; } .wp-show-posts-image > span.cat_links { position: absolute; margin:0; top:auto; bottom: 7.5%; left: 5%; } .wp-show-posts-image > span.cat_links > span > ul{ list-style:none; margin:0; padding:5px; }
We basically just replaced the
generate_inside_featured_image_output
hook from GP default withwpsp_inside_image_container
for WPSP.And since WPSP has a slightly different CSS selector, we simply adjust the CSS selectors. We just changed
.post-image
(GP) to.wp-show-posts-image
(WPSP).Everything else is pretty much the same.
September 18, 2020 at 2:46 pm #19600Liran
ParticipantThanks! I’ll give it a try.
September 18, 2020 at 2:48 pm #19602elvin
ModeratorImportant note:
if ( 77 === $settings['list_id'] )
on this line, make sure you change ’77’ to your WPSP list ID.September 18, 2020 at 2:55 pm #19606Liran
ParticipantWorks like a charm! Do I need to create a new snippet for each list?
September 18, 2020 at 3:14 pm #19608elvin
ModeratorNice one,
Works like a charm! Do I need to create a new snippet for each list?
You definitely can do that if you have multiple WPSP lists and only want to apply it on some.
But if you want this applied on all of your WPSP list, you can simply remove the
if
condition and just do this instead.add_action( 'wpsp_inside_image_container', function( $settings ) { $wpsp_cat_list = get_the_category_list(); $wpsp_category = get_the_category(); if ($wpsp_category) { foreach($wpsp_category as $wpsp_cat) { $wpsp_cat_slug = $wpsp_cat->slug; } } if($wpsp_cat_list){echo '<span class="cat_links"><span class="'.$wpsp_cat_slug.'">'.$wpsp_cat_list.'</span></span>';} });
September 18, 2020 at 3:21 pm #19611Liran
ParticipantGood to know. I appreciate your help, elvin.
September 18, 2020 at 3:53 pm #19613elvin
ModeratorNo problem. We’re always glad to be of any help.:)
February 2, 2021 at 10:41 am #26285José Antonio
ParticipantHi!, is possible add the categories inside the header, just after the title?
Thanks!
February 2, 2021 at 9:13 pm #26292elvin
ModeratorHi Jose,
You can add the categories below the title through the Meta tab. Make sure to check “Include terms” and set its dropdown value to “Below title” as shown here:
https://share.getcloudapp.com/7Kup2lnzFebruary 3, 2021 at 2:19 am #26299José Antonio
ParticipantHi Elvin, thank you very much for your support.
I have not explained myself well, sorry.
I filter my content through a single tag that I have called “featured-home”, but I need to show also only the category it belongs to, not the tag used to filter the content.
So I found the snippet in answer #post-26285
But your snippet puts the span tag right at the beginning:
<div class="wp-show-posts-inner" style=""> <div class="wp-show-posts-image wpsp-image-center"> <span class="cat_links"> <span class="new-products"> <ul class="category tag"> <li><a href="https://contoso.com" rel="category tag">New products</a></li> </ul> </span> </span> <a href="https://contoso.com" title="Buy now"> <img width="680" height="680" src="image.jpg"> </a> </div> <header class="wp-show-posts-entry-header"> <h2 class="wp-show-posts-entry-title"> <a href="https://contoso.com/buy-now/" rel="bookmark">Buy now</a> </h2> </header> <!-- .entry-header --> </div> <!-- wp-show-posts-inner -->
For SEO purposes I would like to place it inside the header tag, just behind the title, this would be my ideal code:
<div class="wp-show-posts-inner" style=""> <div class="wp-show-posts-image wpsp-image-center"> <a href="https://contoso.com" title="Buy now"> <img width="680" height="680" src="image.jpg"> </a> </div> <header class="wp-show-posts-entry-header"> <h2 class="wp-show-posts-entry-title"> <a href="https://contoso.com/buy-now/" rel="bookmark">Buy now</a> </h2> <h3 class="category tag"> <a href="https://contoso.com" rel="category tag">New products</a> </h3> </header> <!-- .entry-header --> </div> <!-- wp-show-posts-inner -->
it’s possible?
Thanks
February 3, 2021 at 9:15 pm #26328elvin
ModeratorAh yes, that’s because the snippet I’ve written was specifically for category overlaying on the featured image.
You should use the
wpsp_after_title
hook to add your code in.add_action('wpsp_after_title',function(){ //do your code here. });
February 8, 2021 at 2:56 pm #26469José Antonio
ParticipantHi Elvin, work fine, thanks!
-
AuthorPosts
- You must be logged in to reply to this topic.