Skip Navigation

[Resolved] View Output Display question

This support ticket is created 3 years, 3 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: Africa/Casablanca (GMT+01:00)

This topic contains 4 replies, has 2 voices.

Last updated by gordonW-2 3 years, 3 months ago.

Assisted by: Jamal.

Author
Posts
#2179069

I have a bunch of content (Image & Text) that I would like to layout dynamically in the following manner.

IMAGE | TEXT
TEXT | IMAGE
IMAGE | TEXT
TEXT | IMAGE

How can I implement this with toolset?

If I was doing this manually outside of wordpress, I would have a query result counter "$ct" and then I'd have a loop like this:

$ct=6; // count of items in returned array
for ($i=$ct;$i>0;$i--) {
if ($i%2==0) { // even
echo "PHOTO | TEXT<br>\n";
} else { // odd
echo "TEXT | PHOTO<br>\n";
}
}

but how can I do this toolset?

thx

#2179523

Hello and thank you for contacting Toolset support.

I assume that you are talking about a view or an archive template, as they are used to display lists, right?

Well, you can either go with a CSS solution, which will let you style the odd and even sections differently. For example:

tr:nth-child(even) {background: #CCC}
tr:nth-child(odd) {background: #FFF}

hidden link

Or you can use a condition on the current index of the loop. Either use a conditional block if you are building with blocks, or use a conditional shortcode, or the wpv-item shortcode if you are building with the legacy editor.
https://toolset.com/documentation/programmer-reference/views/views-shortcodes/#wpv-item

I hope this helps. Let me know if you have any questions.

#2179687

its in a view ... I am using a grid block to make a two column display and i'd like the column contents to alternate sides ... can that be done with CSS?

Otherwise, using a conditional wrapper based off of the current index of the loop ... that is what I want to do, but how do I get the loop index number to test if even or odd?

#2179971

Well, it can be done using CSS, but it may be a bit complicated. Especially because you want to use grids.

So, I gave it a try using the conditional block, but I could not make it work. Because in conditional blocks we do not have a modulo(%) operator. So, I built a custom shortcode, registered it in Toolset settings, then used it in the conditional block.
You can check the results here hidden link

Please log in to my test site with this URL hidden link

1. The custom shortcode that will return 0 or 1 depending on the index of the post in the current loop. This shortcode uses our wpv-loop-index under the hood. I added the code to the theme's functions.php file.

add_shortcode('odd', 'my_odd_function');

function my_odd_function($atts, $content){
	$index = (int) do_shortcode('[wpv-loop-index]');
	return $index % 2;
}

Check it between lines 642-647 in here hidden link

2. The shortcode needs to be registered in the Toolset settings. Check this screenshot hidden link
3. Use the shortcode in conditionals. Check this screenshot hidden link
You will need two conditional blocks, one for odd indexes and the other for even indexes. Check my page here hidden link

I hope this helps. Let me know if you have any questions.

#2180329

Thank you Jamal!

My issue is resolved now. Thank you!