Skip Navigation

[Resolved] Display up to 5 taxonomy terms each post is listed under in archive template

This support ticket is created 4 years, 4 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
- 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+01:00)

This topic contains 2 replies, has 2 voices.

Last updated by Michelle Dodd 4 years, 4 months ago.

Assisted by: Nigel.

Author
Posts
#1403361

I have a directory with CPT of organizations, and each organization is active in several states, which are the taxonomy. I'm creating the archive to list a short bit of info on each organization; this code is needed for the archive.

I have used the solution below to list the total number of states each organization is active in:
https://toolset.com/forums/topic/taxonomy-count-for-a-post/

And below that I need to list only the first 5 states for each organization, and show an ellipsis only if there are more states.

Is this possible?

Thanks!
Michelle

#1403733

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+01:00)

Screenshot 2019-12-10 at 08.10.37.png

Hi Michelle,

yes, that's possible, and you may be able to ditch the custom shortcode you used, too.

You need to create a new View where the Content Selection is your taxonomy.

Set a limit of 6 terms.

Add a Query Filter for the taxonomy terms so that they are set by the "current" post (screenshot).

Update the Loop Editor so that it looks something like this:

[wpv-layout-start]
	[wpv-items-found]
	<p>Total: [wpv-found-count]</p>
	<!-- wpv-loop-start -->
		<wpv-loop>
          [wpv-item index=6]
          ...
          [wpv-item index=other]
          <span class="tax-term">[wpv-taxonomy-title]</span>
		</wpv-loop>
	<!-- wpv-loop-end -->
	[/wpv-items-found]
	[wpv-no-items-found]
	[/wpv-no-items-found]
[wpv-layout-end]

Note that I am using the wpv-found-count to display the total number of terms (which could replace your custom shortcode), and then in the loop section I'm using the wpv-item shortcode to specify that the 6th term, if it exists, will output an ellipsis, while the other terms will be output inside span tags that you can style accordingly. I also removed the No items found text in case any post has no terms assigned.

Lastly, you don't really need the wrapper div, so disable that to simplify the output.

Then insert this View into the loop section of your custom archive where you want it to appear.

#1404733

That is great! Thank you so much for not only thoroughly answering my issue but showing me how and what it does as well so I can learn.

Thank you!
Michelle

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