Skip Navigation

[Resolved] Displaying text only if posts exist

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

This topic contains 2 replies, has 2 voices.

Last updated by marcusC-4 1 year, 3 months ago.

Author
Posts
#2189409

I am trying to display text only if posts exist on my Leader pages.

Here is an example of one that has posts and works great: hidden link

Here is an example of one that doesn't have any posts and I'd like the words Featured In to not display: hidden link

While I'm asking, I'd also like to know if it's possible to change the checkboxes so that instead of being checkboxes, they are buttons. I'd like to make it so you just click on the word (Podcasts, Sermons, Video) instead of clicking checkboxes.

#2189619

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+00:00)

Because the Featured In text appears before the results of the View, if you wanted to use a Conditional block to only show the text if the View had results, you'd effectively need a separate duplicate View performing the same query (or a custom function performing that query) and you'd test whether that View (or custom function) had any results or not to determine whether to show the text.

Naturally, duplicating the query doesn't seem like a very efficient solution.

I think you can use a little trick with CSS instead.

Add some CSS that hides the text by default (you may want to add an ID in the block settings so that you can target it).

Then in the output section of the View add some more CSS that overrides the prior CSS and shows the hidden text.

You can use a custom HTML block to quickly add some CSS, e.g. where you add the Featured In text give that block an ID of, say, text-to-hide, then add a custom HTML block with the following:

<style type="text/css">
  #text-to-hide {
    display: none;
  }
</style>

Then in the output section add a similar custom HTML block that sets the display property to block.

As for the second question, Views doesn't offer any way to customise the appearance of such checkboxes. You can use CSS to essentially hide the native checkbox appearance and replace it with something like a button, say, there are lots of articles online about what is required to achieve something like that.

#2190029

Very clever idea! Thanks 🙂