- This topic has 6 replies, 2 voices, and was last updated 3 years, 4 months ago by Arthur.
-
AuthorPosts
-
November 30, 2020 at 10:37 am #1558956Arthur
I am loving the minimalist approach of GP!
I am trying to set a custom thumbnail size and hide the excerpt for posts, depending on a custom meta field (i.e. ‘meta-box-dropdown’ = ‘Tier 1’ or ‘meta-box-dropdown’ = ‘Tier 2’). I am trying to do so within functions.php using the code below. This however does not filter the posts successfully.
add_filter( 'generate_blog_image_attributes', function( $atts ) { if ( get_post_meta($postid, 'meta-box-dropdown', true) ) { $atts[ 'width' ] = 1900; $atts[ 'height' ] = 300; $atts[ 'crop' ] = false; } // Return our options return $atts; } );
Any suggestions on how to approach?
November 30, 2020 at 1:27 pm #1559242ArthurAs a side note, I have three different loops on my front page. I would like the output of each loop to be different from the main loop. I was able to set up different loops but unsure how to manage the thumbnail sizes and fields within each loop.
/* CUSTOM LOOP FOR HERO POSTS - TIER 1*/ $args = array( 'meta_key' => 'meta-box-dropdown', 'posts_per_page' => 1, 'meta_value' => 'Tier 1', ); $tier1_query = new WP_Query($args); if ( generate_has_default_loop() ) { if ( have_posts() ) : while ( $tier1_query->have_posts() ) : $tier1_query->the_post(); get_template_part( 'content','tier1'); //print get_post_meta( $post->ID, 'meta-box-dropdown', true ); endwhile; /** * generate_after_loop hook. * * @since 2.3 */ do_action( 'generate_after_loop', 'index' ); else : generate_do_template_part( 'none' ); endif; }
December 1, 2020 at 9:14 am #1561156TomLead DeveloperLead DeveloperHi there,
1. It’s better to define a WordPress-created image size. Try this:
add_filter( 'generate_page_header_default_size', function( $size ) { if ( get_post_meta( get_the_ID(), 'meta-box-dropdown', true) ) { return 'my-custom-size'; } return $size; } );
More info here: https://docs.generatepress.com/article/generate_page_header_default_size/
2. Using a method similar to the above should work as long as the meta keys/values are different depending on the loop.
Let me know ๐
December 3, 2020 at 10:52 am #1566245ArthurPerfect thank you Tom!
December 3, 2020 at 2:51 pm #1566493TomLead DeveloperLead DeveloperYou’re welcome ๐
December 7, 2020 at 4:27 pm #1570959ArthurHow would I make this image size apply to the post only on my homepage (index) page and not the post page?
December 7, 2020 at 4:51 pm #1570972ArthurSorry never mind, found the option in Customizer.
-
AuthorPosts
- You must be logged in to reply to this topic.