[Resolved] “Nothing Found” message missing on blog when using content template element

Home Forums Support [Resolved] “Nothing Found” message missing on blog when using content template element

Home Forums Support “Nothing Found” message missing on blog when using content template element

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #2304664
    alco

    Hi, I’m using a modified version of the “Clinic” theme. It uses content template elements in the Blog page/archive. This works fine when there are blog posts present, but when there are no posts the page content is blank rather than showing the standard WordPress “Nothing Found” message.

    Is there a way to bring that message back while still using the content templates? I tried to find a way to add a custom conditional message if no posts are found, but can’t get anything to work. Thanks in advance!

    #2305630
    David
    Staff
    Customer Support

    Hi there,

    for for now, the best method is to create another Block Element to contain your custom No Post Founds message. You can use a Page Hero or any Hook element. Set the Display Rules to match those of your Content Template.

    Make a note of its post ID ( in the Browser URL when editing the post ) and the ID of the content template.

    Then use the following PHP snippet to hide your custom no post element when we have posts, and hide the content template when we don’t have post:

    add_filter( 'generate_element_display', function( $display, $element_id ) {
        if ( 123 === $element_id && have_posts() ) {
            $display = false;
        }
    	
        if ( 456 === $element_id && ! have_posts() ) {
            $display = false;
        }
    
        return $display;
    }, 10, 2 );

    123 change this to the ID of your custom no post element.
    456 change this to the ID of your Content Template.

    #2306064
    alco

    Thanks David, that works!

    #2306510
    David
    Staff
    Customer Support
Viewing 4 posts - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.