- This topic has 3 replies, 2 voices, and was last updated 4 years, 5 months ago by
David.
-
AuthorPosts
-
November 9, 2021 at 12:45 am #1996780
Markus
Hi, I’ve created a custom post type (vacant positions) and created an archive page and a single page for the post type using Block elements – Content template. This works great. Coming from a developer background were I used to do this “the old” way with template files, this really is a smooth way of handling it. I’m using the archive page to show all the vacant positions, using a Block – page hero and a Block – content element. Is there a way to show a different Block element or adjust the current Block element if there are no vacant positions to show, without using code? For example, just showing “Currently there are no vacant positions”.
November 9, 2021 at 4:05 am #1996964David
StaffCustomer SupportHi there,
Thats great to hear – thanks for the feedback!!
at the moment there are minimal options for conditionally displaying the block content. Container Blocks in the Block Element do have:
Remove container conditionin sidebar settings. But it’s limited to No Featured Image or a Post Meta Value.Which leaves us with the code alternative using then
generate_element_displayfilter to swap the Element:https://docs.generatepress.com/article/generate_element_display/
November 9, 2021 at 5:43 am #1997063Markus
Thanks for quick respons! Ok, so one filter for showing the default element and one filter for showing the “no post” element? Got this to work. Do you se any improvements that could be done?
add_filter( 'generate_element_display', function( $display, $element_id ) { global $post; if ( 721 === $element_id && is_post_type_archive('vacant-positions') ) { if ( $post ){ $display = true; } else { $display = false; } } return $display; }, 10, 2 ); add_filter( 'generate_element_display', function( $display, $element_id ) { global $post; if ( 754 === $element_id && is_post_type_archive('vacant-positions') ) { if ( !$post ){ $display = true; } else { $display = false; } } return $display; }, 10, 2 );November 9, 2021 at 6:10 am #1997071David
StaffCustomer SupportThats the way i would do it!
-
AuthorPosts
- You must be logged in to reply to this topic.