I am trying to don't display the headline of the view (not in the loop) if the loop has no-items-found.
I have created a single post template with two nearly identical related post views under the post-content, which are filtered by taxonony category of the single post.
The first view is created with the block editor the second with the legacy editor.
hidden link
has related posts by taxonomy category
hidden link
has no related posts by taxonomy category
The headlines of the view shouldn't appear.
It works fine with the legacy editor by placing the headline behind [wpv-items-found] and an empty [wpv-no-items-found] tag.
But it looks like I can't do this with the block editor? right?
It would be awesome if there would be an option to display any code if the view has no items. By conditional field or functionality of the view itself. Still hoping. Otherwise it looks like I a have to rebuild my views with the classic editor.
Hi,
Thank you for contacting us and I'd be happy to assist.
I can think of two approaches that you can use for this:
1. To include some generic custom CSS code, only when the blocks based view returns no items, you can use the "No Items Found Text" field in the "View Loop" block.
( screenshot: No-Items-Found-Text.png )
Example CSS code:
<style>
body {background: red;}
</style>
2. Alternatively, you can move your heading inside the conditional block, which is placed at the same level as the "View Loop" block, but not inside it.
( screenshot: conditional-block-placement.png )
In the condition settings, you'll set it to show only when number of items found, is greater than or equal to '1'.
( screenshot: conditional-block-condition.png )
regards,
Waqar
The Conditional block "Number of items found in Views is greater than or equal to 1." with the heading placed inside made it.
Missed to check the Conditional setting for "Views Shortcodes". That will help a lot in the feature!
Thank You Wakar!
Update: I think I wrongly chose "very difficult" instead of "very easy". Of course it was very easy;)