We're merging with GenerateBlocks! Learn more here.

[Support request] Show a list only if it has content using conditional?

Please login to receive premium support.

Support for the free plugin can be found here.

Home Forums Pro Support Show a list only if it has content using conditional?

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #8795

    Hi,

    I’m using WPSP to show Event Calendar events in the homepage, in a GeneratePress Element (but I hope to do it using a GP hook). I’m wondering if it’s possible to show a list only if it has content using a conditional?

    Thanks.

    Álvaro

    #8810
    Tom
    Keymaster

    Hi there,

    So you want to check whether the post WPSP is about to display has content, and if it doesn’t, don’t display it?

    Let me know 🙂

    #8811

    Hi Tom,

    Yes, that’s it!

    Thanks

    #8815
    Tom
    Keymaster

    Not sure if it will work, but you could try this function:

    add_filter( 'post_class', function( $classes ) {
        global $post;
    
        if ( ! $post->post_content ) {
            $classes[] = 'no-content';
        }
    
        return $classes;
    } );

    Then you can do this:

    .wp-show-posts .no-content {
        display: none;
    }

    Let me know 🙂

    #9146

    Hi Tom,

    I was sure I had already replied to your comment but seems not…

    Does this apply only to posts-posts or also other post types? I tried it and couldn’t get it to work with the WPSP and Event Calendar events (post_type=tribe_events).

    Also, if I manage this to work, how could I hide the container div, that’s even harder, right?

    Thanks.

    #9163
    Tom
    Keymaster

    The post_class filter would apply to all posts on your website, regardless of post type. The CSS would only apply to posts inside a WPSP list.

    The WPSP container? This would likely be very difficult, unfortunately.

Viewing 6 posts - 1 through 6 (of 6 total)
  • You must be logged in to reply to this topic.