Skip Navigation

[Resolved] conditional when looping

This support ticket is created 4 years, 11 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.

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

Supporter timezone: Asia/Karachi (GMT+05:00)

This topic contains 10 replies, has 2 voices.

Last updated by Waqar 4 years, 11 months ago.

Assisted by: Waqar.

Author
Posts
#1415369

I have a loop that works as it is but i have a field "packsuppliers-status"
And if this is 1 the content will be shown.

[wpv-conditional if="( $(packsuppliers-status) eq '1' )"] [/wpv-conditional]

this work, so far so good.
BUT
when have Grid view i really dont know where to put this conditional so i don not mess up the bootstrap grid.
The grid is 4 columns and i ONLY whant to show content from the post with packsuppliers-status = 1 and the content fill up nice and not with alot of empty spaces/columns. if i put [wpv-conditional if="( $(packsuppliers-status) eq '1' )"] right after <!-- wpv-loop-start -->

-----This is in the loop editor:------

[wpv-layout-start]
[wpv-items-found]
<!-- wpv-loop-start -->
<div class="container wpv-loop js-wpv-loop">
<wpv-loop wrap="4" pad="true">
[wpv-item index=1]
<div class="row ">
<div class="col-md-3">[wpv-post-body view_template="loop-item-in-packsuppliers-only-active-co"]</div>
[wpv-item index=2]
<div class="col-md-3">[wpv-post-body view_template="loop-item-in-packsuppliers-only-active-co"]</div>
[wpv-item index=3]
<div class="col-md-3">[wpv-post-body view_template="loop-item-in-packsuppliers-only-active-co"]</div>
[wpv-item index=4]
<div class="col-md-3">[wpv-post-body view_template="loop-item-in-packsuppliers-only-active-co"]</div>
</div>
[wpv-item index=pad]
<div class="col-md-3"></div>
[wpv-item index=pad-last]
<div class="col-md-3"></div>
</div>
</wpv-loop>
</div>

<!-- wpv-loop-end -->
[/wpv-items-found]
[wpv-no-items-found]
[wpml-string context="wpv-views"]No items found[/wpml-string]
[/wpv-no-items-found]
[wpv-layout-end]

------- THIS is the VIEW - this shall only shows up if packsuppliers-status=1 ------

<div class="member-box">
<div class="member-logo">[wpv-post-featured-image size="full" class="member-logo-gallery"]</div>
<h3 class="member-company">[wpv-post-link]</h3>
[wpv-conditional if="( $(wpcf-address) ne '' )"][types field="address"][/types]<BR>[/wpv-conditional]
[wpv-conditional if="( $(wpcf-postal-number) ne '' )"]<i class="fa fa-" aria-hidden="true"> [types field="city"][/types]<BR>[/wpv-conditional]
[wpv-conditional if="( $(wpcf-city) ne '' )"]<i class="fa fa-mobile" aria-hidden="true"> [types field="mobile"][/types]<BR>[/wpv-conditional]
[wpv-conditional if="( $(wpcf-country) ne '' )"]<i class="fa fa-envelope" aria-hidden="true"> [types field="country"][/types]<BR>[/wpv-conditional]
[wpv-conditional if="( $(wpcf-website) ne '' )"]<i class="fa fa-home" aria-hidden="true"> [types field="website" target='_blank' title='Hemsida'][/types]<BR>[/wpv-conditional]
</div>

#1416235

Hi Patrik,

Thank you for contacting us and I'd be happy to assist.

Since, in this case, the number and position of result items that we need to show through that condition, is not known, the content in the view's "Loop Editor" can be simplified to:
( only showing the content between <!-- wpv-loop-start --> and <!-- wpv-loop-end --> tags )


<!-- wpv-loop-start -->

<div class="container wpv-loop js-wpv-loop">
	<wpv-loop>
		<div class="row">
			[wpv-conditional if="( $(packsuppliers-status) eq '1' )"]
			<div class="col-md-3">[wpv-post-body view_template="loop-item-in-packsuppliers-only-active-co"]</div>
			[/wpv-conditional]
		</div>
	</wpv-loop>
</div>

<!-- wpv-loop-end -->

As a result, the result items in each row won't be wrapped in a new row class container div, but it should not have any visible impact on the grid layout itself.

I hope this helps and please let me know if you need any further assistance around this.

regards,
Waqar

#1416483
aaaa1.JPG

Hello,
thank you.
But this did almost the trick.
it does show only the packsuplier-status=1 but the grid is still messed up and all come in one line under each other,.
Is should show up where i show in the image 2, 3, 4, etc 🙂

i use this
[wpv-layout-start]
[wpv-items-found]
<!-- wpv-loop-start -->
<div class="container wpv-loop js-wpv-loop">

<wpv-loop>

<div class="row">

[wpv-conditional if="( $(packsuppliers-status) eq '1' )"]

<div class="col-md-3">[wpv-post-body view_template="loop-item-in-packsuppliers-only-active-co"]</div>

[/wpv-conditional]

</div>

</wpv-loop>

</div>

<!-- wpv-loop-end -->
[/wpv-items-found]
[wpv-no-items-found]
[wpml-string context="wpv-views"]No items found[/wpml-string]
[/wpv-no-items-found]
[wpv-layout-end]

#1416515

Can you make a private chanel so can i give you access to the site if you like to try ?
you can se result here
hidden link

#1417541

Hi Patrik,

Thanks for sharing the update.

I've set your next reply as private so that you can share the temporary admin login details.

Note: Please make a complete backup copy before sharing the access details.

regards,
Waqar

#1418439

Hi Patrik,

Thank you for sharing the admin access and I apologize for a typo in the code example that I shared with you earlier.

The div with "row" class needed to be outside the loop, like this:


<!-- wpv-loop-start -->
 
<div class="container wpv-loop js-wpv-loop">
	<div class="row">
		<wpv-loop>   
			[wpv-conditional if="( $(packsuppliers-status) eq '1' )"]
			<div class="col-md-3">[wpv-post-body view_template="loop-item-in-packsuppliers-only-active-co"]</div>
			[/wpv-conditional]  
		</wpv-loop>
	</div>
</div>
 
<!-- wpv-loop-end -->

I've updated the same in your view too and the grid layout is now fixed.
( screenshot: hidden link )

Hope this helps and once again my sincere apologies for the incorrect code example.

regards,
Waqar

#1418445

I wish you a very marry X-mas!!! And thank you SO much!!!!
It works like a charm!!!

#1418563
111.JPG

Can i ask you a new question connected to this issue ?
Im trying toi make a "slider" with these logos thats active.
But i can only get the "Post link" to slide. the Post feature image dont show.
can you make next post personal so i can send you some links in admin where i have the views, slings and so on...

the slide works. but only titel is "sliding" 🙂

#1422869

Hi Patrik,

Thanks for the update and glad that it works.

I've checked the screenshot and it seems you're referring to the view "Packsuppliers FrontSlider".

While looking into some of the "Packsuppliers" type posts, I couldn't find any featured images attached to them.
( example screenshot: hidden link )

Can you please attach featured images to those posts and then check the slider page again?

Let me know how it goes and for a new question or concern, you're welcome to start a new ticket.

Happy Holidays and marry X-mas 🙂

regards,
Waqar

#1422947

thanks, but theres an issue anyway. 🙂
As earlier posts i have to use [wpv-conditional if="( $(packsuppliers-status) eq '1' )"]
and only show the active. All active have an featured image. Now when i have my loop like you did before in the posts
i dont se even the title. Now i get no results at all-

---this is the loop---

[wpv-layout-start]
[wpv-items-found]
<!-- wpv-loop-start -->
<wpv-loop>
[wpv-conditional if="( $(packsuppliers-status) eq '1' )"]
[wpv-post-body view_template="Packsuppliers FrontSlider - slide"]
[/wpv-conditional]

</wpv-loop>
<!-- wpv-loop-end -->
[/wpv-items-found]
[wpv-no-items-found]
[wpml-string context="wpv-views"]No items found[/wpml-string]
[/wpv-no-items-found]
[wpv-layout-end]

---This is the template---
[wpv-post-link]
[wpv-post-featured-image size="custom" width="250" height="75" class="packsuppliers-img-slide"]

#1424657

Thanks for writing back and I assume, we're still discussing the view "Packsuppliers FrontSlider".
( view_id: 203190 )

There are a total of 1207 "Packsuppliers" posts out of which only 73 have active(1) selected for the "packsuppliers-status" field.

This means that due to that conditional check only these 73 posts will qualify to show any content.

But since the view is also set to show only 1 post per page and in a random order, whenever a post with a different value for this field will become available on a page, no content will be shown.

If you'd like to show results with the pagination enabled, it would be better to remove the conditional check from the "Loop Editor" section and instead, include a query filter that brings in only those posts which have the "packsuppliers-status" field value equal to 1, on the first place.

Example screenshot: hidden link

This way, you'll not have to restrict the results at the loop's content level using the conditional check.