Skip Navigation

[Resolved] Bootstrap grid with conditional

This support ticket is created 6 years, 9 months ago. There's a good chance that you are reading advice that it now obsolete.

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.

No supporters are available to work today on Toolset forum. Feel free to create tickets and we will handle it as soon as we are online. Thank you for your understanding.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 -
- 13:00 – 18:00 13:00 – 18:00 13:00 – 18:00 14:00 – 18:00 13:00 – 18:00 -

Supporter timezone: America/Jamaica (GMT-05:00)

This topic contains 7 replies, has 2 voices.

Last updated by Shane 6 years, 9 months ago.

Assisted by: Shane.

Author
Posts
#548376

I am trying to: output a grid of posts but skip those where a field does not meet a requirement

I have inserted a [wpv-conditional] into the content template for the grid cell output but of course when this conditional is not met, the output is blank so I end up with a grid of some filled and some empty cells. What ideally I would like to do is to have the loop jump over the item and go to the next post if the current post does not meet the conditional.

I can't see how to do this.

Incidentally, when I include a [wpv-conditional] in a "template for this view" box, it is ignored but if I create a new content template and refer to that instead, then the conditional is seen...I don't know if this is a bug?

Thanks

Nick.

#548427

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Nick,

Thank you for contacting our support forum.

Could you send me a copy of the code structure for the view loop so that I can have a look at how it was setup ?

Thanks,
Shane

#548460

Thanks Shane.

Here is the view loop:

[wpv-layout-start]
	
    [wpv-items-found]
    <!-- wpv-loop-start -->
    
   
	<wpv-loop wrap="6" pad="true">
		[wpv-item index=1]
		<div class="row ">
			<div class="col-sm-2">[wpv-post-body view_template="Shows grid"]</div>
		[wpv-item index=other]
			<div class="col-sm-2">[wpv-post-body view_template="Shows grid"]</div>
		[wpv-item index=6]
			<div class="col-sm-2">[wpv-post-body view_template="Shows grid"]</div>
		</div>
		[wpv-item index=pad]
			<div class="col-sm-2"></div>
		[wpv-item index=pad-last]
			<div class="col-sm-2"></div>
		
</wpv-loop>
	 <!-- wpv-loop-end -->
    [/wpv-items-found]
[wpv-layout-end]

and here is the content template :

[wpv-noautop]   
        [wpv-conditional if="( $(show_active) eq 'on' )"]
        <div class="constant-100pc-300">
                  <div class="image">
           <a href="[wpv-post-url]">[wpv-post-featured-image size='portfolio-full']</a>
          <grid-title-overlay><span>[wpv-post-title output='sanitize']</span></grid-title-overlay>
           <slider-head14><span>[wpv-post-excerpt length="16" count="word"]</span></slider-head14>
            <slider-head12><span>[wpv-conditional if="([wpv-post-field name='show_user_list'] lt '9999')"] with [wpv-user field="display_name" id="[wpv-post-field name='show_user_list']"]</span>[/wpv-conditional]</slider-head12>    
          </div>
        </div>           
         [/wpv-conditional]
       [wpv-conditional if="( $(show_active) neq 'on' )"]
<p></p>
       [/wpv-conditional]
[/wpv-noautop]

You can see that for now I am outputting just a paragraph break when content with "show_active" not set to "on" is encountered but ideally I'd be skipping that item and checking the next.

#548470

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Nick,

Try wrapping the conditional around each of these

<div class="col-sm-2">[wpv-post-body view_template="Shows grid"]</div>

Instead of the body code itself.

Thanks,
Shane

#549399

Thanks Shane.

That doesn't seem to solve the problem as you can see here: hidden link

The view is now:

[wpv-layout-start]
	
    [wpv-items-found]
    <!-- wpv-loop-start -->
    
   
	<wpv-loop wrap="6" pad="true">
		[wpv-item index=1]
		<div class="row ">
			[wpv-conditional if="( $(show_active) eq 'on' )"]<div class="col-sm-2">[wpv-post-body view_template="Shows grid"]</div>[/wpv-conditional]
		[wpv-item index=other]
			[wpv-conditional if="( $(show_active) eq 'on' )"]<div class="col-sm-2">[wpv-post-body view_template="Shows grid"]</div>[/wpv-conditional]
		[wpv-item index=6]
			[wpv-conditional if="( $(show_active) eq 'on' )"]<div class="col-sm-2">[wpv-post-body view_template="Shows grid"]</div>[/wpv-conditional]
		</div>
		[wpv-item index=pad]
			<div class="col-sm-2"></div>
		[wpv-item index=pad-last]
			<div class="col-sm-2"></div>
		
</wpv-loop>
	 <!-- wpv-loop-end -->
    [/wpv-items-found]
[wpv-layout-end]

and the content template is :

[wpv-noautop]   
         
           <div class="constant-100pc-300">
                  <div class="image">
           <a href="[wpv-post-url]">[wpv-post-featured-image size='portfolio-full']</a>
          <grid-title-overlay><span>[wpv-post-title output='sanitize']</span></grid-title-overlay>
           <slider-head14><span>[wpv-post-excerpt length="16" count="word"]</span></slider-head14>
            <slider-head12><span>[wpv-conditional if="([wpv-post-field name='show_user_list'] lt '9999')"] with [wpv-user field="display_name" id="[wpv-post-field name='show_user_list']"]</span>[/wpv-conditional]</slider-head12>    
          </div>
        </div>
    

[/wpv-noautop]

Thanks

#549481

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Nick,

What you can do is to add a fixed filter to the view so that it only allows you to search for posts that are on. This will allow you to not use the conditionals to filter the items. Please add a query filter for this and let me know if it helps.

Thanks,
Shane

#549743

Thanks Shane. I added a filter in the filter editor as follows but this means I need to pass a url parameter when loading the page which "kind of works" but isn't ideal. I can't work out how to write the filter in a way which filters only to show_active="on" which doesn't seem to work.

<div style="display:none"><label>[wpml-string context="wpv-views"]show_active[/wpml-string]</label>[wpv-control-postmeta field="show_active" type="textfield" url_param="wpv-show_active"]
    </div>
#549975

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Nick,

A URL parameter should not be necessary. Would you mind providing me with admin access for the view so that I can have a look at the filter on the backend ?

The private fields will be enabled for your next response.

Thanks,
Shane

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.