Archived topic
How do I add a custom layout for empty archive
4 replies · Started by Abdul Khaliq on March 4, 2023
The Query Loop in GenerateBlocks allows us to set up a custom layout if the archive is blank.
But the Query Loop in GenerateBlocks Pro does not have this feature.
Is there any way to setup a custom layout for an empty archive?
Hi there,
when you say an empty archive ? how is it empty ?
I mean there are no posts related to that specific archive
So, when there is nothing in archive, how do I display a random message or anything else such as "currently there no posts to display in this archive/category."
Hi there,
You can create a block element - loop template at appearacne > elements.
Add the content you want to show for the no result archive page.
Set the location to all archives or category archives according to your needs, then publish the element.
Add this PHP snippet so the element will only work when the archive has no posts, replace 100 with your element id which can be found in the URL of the element editor:
add_filter( 'generate_element_display', function( $display, $element_id ) {
if ( 100 === $element_id && have_posts() ) {
$display = false;
}
return $display;
}, 10, 2 );