Skip Navigation

[Gelöst] Changing row-colors in a view

Dieser Thread wurde gelöst. Hier ist eine Beschreibung des Problems und der Lösung.

Problem:
How to create striped results for a View output?

Solution:
Add different classnames for each loop iteration, either by using the even and odd values for the index attribute of the wpv-item shortcode, or as described below using the index=1 and index=2 attributes and adding the wrap="2" attribute to the wpv-loop tag to make them repeat: https://toolset.com/forums/topic/changing-row-colors-in-a-view/#post-1128171

Relevant Documentation:
https://toolset.com/documentation/user-guides/views-shortcodes/#wpv-item

This support ticket is created vor 6 Jahren, 1 Monat. 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
- 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 -
- 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 -

Supporter timezone: Europe/London (GMT+00:00)

Dieses Thema enthält 2 Antworten, hat 2 Stimmen.

Zuletzt aktualisiert von thomasR-9 vor 6 Jahren, 1 Monat.

Assistiert von: Nigel.

Author
Artikel
#1128092

Tell us what you are trying to do?
I have a view with results. Each result is displayed in a row. I want to change the color of every second row. How can I do this?
This is the code:
<div class="row" style="padding-top:21px;">
<AlternatingRowStyle CssClass="danger" />
<div class="col-sm-3"><h4>[wpv-post-title]</h4>[types field='heldenbild' title='%%TITLE%%' alt='%%ALT%%' size='full'][/types]<br>
</div>
<div class="col-sm-6">[types field='kurzbeschreibung'][/types]</div>
<div class="col-sm-3">Webseite:<br>[types field='webseite' target='_blank'][/types]<br><br>
Schwerpunkt:<br>[wpv-post-taxonomy type="heldenkategorie" separator=" | "]</div>
</div>
<br><hr>

Is there any documentation that you are following?
No

Is there a similar example that we can see?
No.

What is the link to your site?
versteckter Link

#1128171

Nigel
Supporter

Sprachen: Englisch (English ) Spanisch (Español )

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

Screenshot 2018-10-16 at 11.26.30.png

Hi Thomas

You need to use the wpv-item shortcode for the first and second iterations and add the wrap attribute to the wpv-loop tag so that these are applied for every nth iteration and not just the first.

So the loop editor looks like this:

[wpv-layout-start]
	[wpv-items-found]
	<!-- wpv-loop-start -->
	<wpv-loop wrap="2" pad="true">
		[wpv-item index=1]
			<div class="stripe-red">[wpv-post-body view_template="Loop item in Striped View"]</div>
		[wpv-item index=2]
			<div class="stripe-green">[wpv-post-body view_template="Loop item in Striped View"]</div>
	</wpv-loop>
	<!-- wpv-loop-end -->
	[/wpv-items-found]
	[wpv-no-items-found]
		<strong>[wpml-string context="wpv-views"]No items found[/wpml-string]</strong>
	[/wpv-no-items-found]
[wpv-layout-end]

I'm simply adding different class names to every 1st and 2nd iteration (results in the screenshot).

These are documented here: https://toolset.com/documentation/user-guides/views-shortcodes/#wpv-loop

You can see an example most easily whenever you use the Loop Wizard to insert a structure such as the Bootrap grid or list output formats.

#1128396

My issue is resolved now. Thank you!