Skip Navigation

[Resolved] Conditional Output on a filtered listing

The Toolset Community Forum is closed, for technical support questions, please head on to our Toolset Professional Support (for paid clients), with any pre-sale or admin question please contact us here.
This support ticket is created 7 years, 8 months ago. There's a good chance that you are reading advice that it now obsolete.
This is the community support forum for Types plugin, which is part of Toolset. Toolset is a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients and people who registered for Types community support can post in it.

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 4 replies, has 2 voices.

Last updated by fuel-tvE 7 years, 8 months ago.

Assisted by: Nigel.

Author
Posts
#506023

Hello,

I trying to list content from a custom post-type (Movies), filtered with it's taxonomy (Movie Types) terms (thriller, Action, Comedy, ...), for this I'm using a view (display intems using custom search) and on the Filter Editor I'm using radio buttons to filter the listing using the taxonomy.

Till this point, everything is working great, I have a page using this view and I'm able to select comedy and only list the posts associated with this term.

But I would like to also list a text description based on each term, example:
On Movies Page:

Radio Filter controls:
Selected: Comedy

- Comedy description - (conditional output html or text block)
- List of Posts with taxonomy Comedy associated -

I already tried using conditional output on text blocks, with every condition possible, looked upon all the documentation and everything, but can't seem to make it work.

Wich conditional output term should I use and where do I use it (just after the controls on filter editor or just before the loop starts?)

Should I use other logic? like using taxonomy terms descriptions?

I'm using the option "Update the View results every time an input changes" and also "Update URLs after loading search results".

Is it understandable or should i explain it better?
Thanks for the help.

#506104

Nigel
Supporter

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

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

Hi Eduardo

If you have created a view to show your movies by taxonomy then added it to a page, the problem is that outside the loop itself (the search results) the information about the taxonomy term isn't available to the Views shortcodes.

If you try outputting wpv-post-taxonony inside your loop it will correctly output the taxonomy term, but if you try to use it elsewhere on the same page then the post it is trying to output the taxonomy of is the page where the view is inserted (which, naturally, doesn't have it).

I would add the description you require for the taxonomy to the taxonomy term itself, and then output that in the right place using [wpv-post-taxonomy type="content-type" format="description"].

By the right place, this has to come inside the loop, which means you will only want to output it for the first iteration of the loop, something like this:

<wpv-loop>
	[wpv-item index=1]
        <h2>[wpv-post-taxonomy type="content-type" format="name"]</h2>
		<p>[wpv-post-taxonomy type="content-type" format="description"]</p>

		<p>[wpv-post-link]</p>
		<!--- normal loop stuff for first iteration -->
	[wpv-item index=other]
		<p>[wpv-post-link]</p>
		<!--- normal loop stuff for other iterations -->
</wpv-loop>
#506215
Custom Search View.png

Hi Nigel,

Thanks for your help, but it didn't worked.
I attached a screenshot with my custom view settings, that may help you understand my view settings.

All I want is a text description between the filters and the custom post type posts results, that will be different based on the taxonomy selected.

When I tried your code, I selected the taxonomy filter and no result showed.

Is it possible?
Thanks,

#506288

Nigel
Supporter

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

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

Hi Eduardo

As I described above, you can only output the information about what the "current" taxonomy term is on your search page inside the loop output section, because outside that the post from which the taxonomy information would be taken is the page where you are adding the view (which doesn't have it).

Alternatives where you could access the taxonomy information would be to create a taxonomy archive (but you can't filter by the same taxonomy on a taxonomy archive) or by creating nested views with the outer view a taxonomy view which lists the taxonomy terms and an inner view which lists the posts for that term, but the problem in this case is that you can't use search filters on a taxonomy view.

Which means going back to the proposal above.

Let me first make one observation, which is that your view loop output section links to a content template "Loop item in view for detail filtered", and all that content template contains is a call to another content template "content-for-detail-page". So the first of these is redundant, you can just link directly to the content-for-detail-page view directly from the loop output section.

So your loop output section will need to look like this:

<wpv-loop>
    [wpv-item index=1]
    	[wpv-conditional if="( is_being_filtered() eq 'true' )"]
	    <h2>[wpv-post-taxonomy type="content-type" format="name"]</h2>
    	    <h3>[wpv-post-taxonomy type="content-type" format="description"]</h3>
    	[/wpv-conditional]
		<li>[wpv-post-body view_template="content-for-detail-page"]</li> 

    [wpv-item index=other]
		<li>[wpv-post-body view_template="content-for-detail-page"]</li>
        
</wpv-loop>

You will also need to register a custom function to check whether a filter is being applied for the taxonomy, by adding the following to your theme's functions.php file or using a plugin such as Code Snippets. Note that you will need to edit the taxonomy slug (which in my example is 'content-type').

function is_being_filtered() {

	$taxonomy = 'content-type'; // edit as required

	if ( isset( $_GET['wpv-' . $taxonomy] ) ) {

		if ( '0' != $_GET['wpv-' . $taxonomy] ) {

			return "true";
		}
	}
	return false;
}

That function checks whether a url parameter for the taxonomy filter has been added, and you will need to register it to be used in the conditional shortcode at Toolset > Settings > Front-end Content.

Then the way this works is that for the first item in the loop it will output the name and the description of the taxonomy term assigned to that post. But we don't want to display it when your radio filter is set to display all (e.g. on initial page load), which is why we add the conditional shortcode to check whether the filter is being applied or not.

I don't believe there is another way of doing this that doesn't extract the taxonomy information from the first filtered result, which means you may need to use some CSS to make the taxonomy title and description stand out from the list of post results.

#506526

Nigel,

You're the man!
Thank you so much, finally worked!

Really stoked that it worked out, thanks once again!

Best Regards,
Eduardo R.

The forum ‘Types Community Support’ is closed to new topics and replies.