Skip Navigation

[Resolved] Displaying view by taxonomies url in the archieve loop

This support ticket is created 6 years, 1 month 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+00:00)

This topic contains 8 replies, has 2 voices.

Last updated by Akhil 6 years ago.

Assisted by: Nigel.

Author
Posts
#1120212

Hi ,

i am trying to create a few different template for few taxonomies , it shoud detect the url for taxonomies and output related view / template.

How can i achieve this pls ?
i read the doc here : https://toolset.com/documentation/user-guides/conditional-html-output-in-views/displaying-taxonomies-conditionally/ i find nothing that related.
Not sure why this code work work ?

some info : tax slug = dir , tax = services, url : ..../dir/services

[wpv-conditional if="( '[wpv-taxonomy-title]' eq 'dir' ) OR  ( '[wpv-taxonomy-slug]' eq 'dir' ) OR  ( '[wpv-taxonomy-url]' eq 'dir' )"]
<strong>dir template </strong>
[/wpv-conditional]
#1120768

Nigel
Supporter

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

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

Where are you using this?

Is this intended to work with taxonomy archives, and you want to display different content depending on which term the archive is for?

#1120968

Hi. will be using it at custom post type archieve, layout,

Yes > to display different content depending on which term the archive is for.

i hope to create few sets of listing loop template [view ] for different taxonomies.

#1121600

Nigel
Supporter

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

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

There is a basic problem with using the wpv-taxonomy-title and similar shortcodes, in that the only context they work in is in taxonomy Views (i.e. a View which lists taxonomy terms and not posts).

We have an internal ticket to expand the scope so that they also work in taxonomy archives.

In the meantime you'll need a custom shortcode to return the term of the current taxonomy archive.

I have written a generic taxonomy shortcode which will work both outside of the loop and within the loop on the taxonomy archive pages, and depending on the attributes you provide you can output any of the taxonomy (slug), the term name, the term slug, the term id, the term description, the count of results, or you can also use it to output term meta for the current term by specifying the field.

Here's the code to register the shortcode:

<?php
/**
 * Register shortcode to output current taxonomy
 * for use on taxonomy archive page outside or inside loop
 * att['output'] string taxonomy | name (default) | slug | term_id | description | count | field (requres att['field'])
 * att['field'] string key
 */
add_shortcode('taxonomy', function ($atts = [], $content = null) {

	// provide defaults
	$atts = shortcode_atts(
		array(
			'output' => 'name',
			'field' => '',
		),
		$atts
	);
	extract($atts);

	$return = '';

	global $wp_query;
	$obj = $wp_query->get_queried_object();

	if ($output != 'field') {

		$return = $obj->$output;
	} else {
		if (isset($field)) {
			$return = get_term_meta($obj->term_id, $field, true);
		}
	}

	return $return;
});

And here are some examples of using it:

[taxonomy output='taxonomy'] -- outputs the taxonomy slug
[taxonomy] -- outputs the term name (default)
[taxonomy output='count'] -- outputs the count of results
[taxonomy output='field' field='wpcf-colour'] -- outputs a 'colour' taxonomy custom field

(You should be able to use it in wpv-conditional shortcodes after registering the custom shortcode at Toolset > Settings > Front-end Content.)

#1123304

thank you , amazing work,

i've added the shortcode at both 'Third-party shortcode arguments' and also the
'Functions inside conditional evaluations ' but i dont get the results desired.

this works:

[wpv-conditional if="('[taxonomy output='count' ]' eq '3' )" debug="true"]
3 listings for : [taxonomy output='taxonomy']
[/wpv-conditional]

this doesnt work :

[wpv-conditional if="('[taxonomy output='taxonomy' ]' eq 'eat-drink' )" debug="true"]
eat drink
[/wpv-conditional]

 [wpv-conditional if="('[taxonomy ='taxonomy' ]' eq 'Eat & Drink' )" debug="true"]
eat drink
[/wpv-conditional]

for the last code the debug value is valid but there is no output .

i think it need to fetch the last taxomies [subcategories] in the shortcode ?

thanks

#1123492

Nigel
Supporter

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

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

I just tested this on my site and it is working as expected, so let me just confirm how you are trying to use it.

I have a status taxonomy, with hierarchical terms archived > to-delete (these are all slugs).

So when I am on the archive @site.com/status/archived/to-delete/ then this will output the term name ("To Delete"):

      [wpv-conditional if="( '[taxonomy output='slug']' eq 'to-delete' )"]
      [taxonomy output='name']
      [/wpv-conditional]

[taxonomy output='taxonony'] would be outputting the slug of the taxonomy (not of any taxonomy terms), so in my example above it would output "status".

Where exactly are you using the taxonomy shortcode?

#1123609

thanks . ill try again and reply soon.
ill be using it at the sub- Templates for the WordPress Archive .

#1125233

Nigel
Supporter

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

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

I'm not sure if you still need help with this, it's related to the other threads where we have been discussing your archive pages, but I'll mark as awaiting feedback from you in any case.

#1125884

My issue is resolved now. Thank you!