- This topic has 5 replies, 2 voices, and was last updated 6 years ago by Tom.
-
AuthorPosts
-
March 1, 2018 at 8:56 am #509018Peter
Hi GP support,
I hope I’m not too much of a burden for your support, but I am really struggling trying to get your magnificent GP theme to behave like I want it to… maybe I am asking too much…
The thing is that I am trying to build an Aviation website with a News category where I would like to use the Featured Image option – for just that category.
At the same time there’s a number of other categories where I do not want to utilize the Featured Image option.
The reason for this has to do with the way I build the other pages and posts; by using a 70/30 grid for manual content and many many manual sidebars.
I could probably use Elementor page builder for that, but I don’t want a Page Builder – it’s not good for SEO and load times.
I am however adding a featured image to (almost) all posts – the reason is that I want the featured images to appear on Archive-pages, where there are grids with all posts in a specific category.
So I thought I’d use Hooks!
I’ve written a hook (snatched from somewhere):
`<?php if ( has_post_thumbnail() || is_category( $category = ‘nyheder’ ) ) : ?>
<a href=”<?php the_post_thumbnail_url(); ?>” title=”<?php the_title_attribute(); ?>”>
<img src=”<?php the_post_thumbnail_url(); ?>”/>
</a>
<?php endif; ?>`
The intention behind the hook is to only show Featured Image for the category “Nyheder” (News) and at the same time keep the lightbox functionality.But there are still Featured Images loaded on all posts – even though I have set up the Blog add-on to only show Featured Images on Archive pages.
Hopefully someone can help – I would be very very greatful.
Thanks.
Peter
March 1, 2018 at 8:48 pm #509370TomLead DeveloperLead DeveloperHi Peter,
Give this function a try:
add_filter( 'option_generate_blog_settings', 'tu_dynamic_featured_images' ); function tu_dynamic_featured_images( $options ) { if ( is_category( 'nyheder' ) ) { $options['post_image'] = true; } $options['post_image'] = false; return $options; }
Adding PHP: https://docs.generatepress.com/article/adding-php/
Let me know if this helps or not ๐
March 2, 2018 at 2:37 am #509493PeterHi Tom,
Thanks very much for your reply.
I have dropped the idea of achieving what I want by a hook and instead I have put the two filters in my child theme’s functions.php.
One filter that should display Featured Image in just one category:
add_filter( 'option_generate_blog_settings', 'tu_dynamic_featured_images' ); function tu_dynamic_featured_images( $options ) { if ( is_category( 'nyheder' ) ) { $options['post_image'] = true; } $options['post_image'] = false; return $options; }
One filter that should hide Feat.img. in the specified categories:
add_filter( 'generate_single_featured_image_output', 'tu_remove_single_post_image' ); function tu_remove_single_post_image( $output ) { if ( in_category( 'business-jet'&&'passager-fly'&&'passager-fly-jet' ) ) { return ''; } return $output; }
I have then set the Blog add-on to show Featured Image everywhere – and to not show it at all. I’ve tried both.
But things are not working out as I supposed they would.
I can send you WP-acces in a private message or e-mail if you think you could find the time to have a look.
In any case: Thank you for your time.
cheers
Peter
March 2, 2018 at 9:48 pm #510236TomLead DeveloperLead DeveloperThe first snippet should definitely work. It will only work when you’re viewing the category archive that matches that slug.
The second snippet isn’t correct the correct PHP syntax. It should be this:
add_filter( 'generate_single_featured_image_output', 'tu_remove_single_post_image' ); function tu_remove_single_post_image( $output ) { if ( in_category( array( 'business-jet', 'passager-fly', 'passager-fly-jet' ) ) ) { return ''; } return $output; }
March 5, 2018 at 12:26 am #511753PeterHi Tom,
Thank you very much for your reply.
I will give it a try.
Right now it seems I have managed to solve the problem – or some of it – by CSS styling for specific categories.
Thanks again for your time.
cheers
PeterMarch 5, 2018 at 8:46 am #512113TomLead DeveloperLead DeveloperNo problem ๐
-
AuthorPosts
- You must be logged in to reply to this topic.