Site logo

[Support request] How do I add a custom layout for empty archive

Home Forums Support [Support request] How do I add a custom layout for empty archive

Home Forums Support How do I add a custom layout for empty archive

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #2554886
    Abdul Khaliq

    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?

    #2555246
    David
    Staff
    Customer Support

    Hi there,

    when you say an empty archive ? how is it empty ?

    #2555257
    Abdul Khaliq

    I mean there are no posts related to that specific archive

    #2555259
    Abdul Khaliq

    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.”

    #2555862
    Ying
    Staff
    Customer Support

    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 );
Viewing 5 posts - 1 through 5 (of 5 total)
  • You must be logged in to reply to this topic.