I need a help in category solution that if all categories are selected then only a specific category show in page template via [wpv-post-taxonomy type="product_cat"] or only top most category show.
This mean
if (all_category_selected){
print ("specific category" or "top most category")
}else{
print ("only selected category")
}
Is this possible to achieve in toolset?
Please help me to achieve this.
If we selected all category then [wpv-post-taxonomy type="product_cat"] display only "Top most category" (Parent of all).
and if we selected any category but not all (like business and education) then [wpv-post-taxonomy type="product_cat"] display only selected category (like business and education).
Is this possible? If yes then how to achieve this?
There isn't any way to filter the output of a Views shortcode like wpv-post-taxonomy, so the problem would be that you want it to output normally in most cases, but not output anything at all in the particular case where all categories were selected so that you could then output something else (i.e. the top level category).
So you have two options.
One is that you will need to write a custom shortcode which essentially does the same as wpv-post-taxonomy but has the logic built-in to only display the top-level category when required.
The other is to use conditional shortcodes.
You need to compare the output of wpv-post-taxonomy to the list of all the categories, and if they are the same output the top level category directly as a string, and if they are different then output wpv-post-taxonomy as normal.
The best way to generate the list of all categories to include in the wpv-conditional shortcode is to create a post that has all of the categories selected and display it using a template which includes wpv-post-taxonomy so that you can copy and paste the results into your conditional shortcode test.
We have an imminent release of Views due (should be later today) which improves on the UI for inserting conditional shortcodes, and includes taxonomies, it will be easier to achieve when that update is available.
Nigel is on vacations and will be back tomorrow, but I'll be happy to assist while he is away.
The plugin updates that Nigel mentioned earlier have been released.
After updating all Toolset plugins, to their most recent versions, you can follow these steps:
1. Please create a role model post, which should have all the categories assigned to it. This post will be used for the comparisons.
2. In your content template, you can use the conditional blocks like this:
[wpv-conditional if="( '[wpv-post-taxonomy type="category-slug" item="123" format="slug"]' eq '[wpv-post-taxonomy type="category-slug" format="slug"]' )"]
This one has all categories!
[/wpv-conditional]
[wpv-conditional if="( '[wpv-post-taxonomy type="category-slug" item="123" format="slug"]' ne '[wpv-post-taxonomy type="category-slug" format="slug"]' )"]
This one has only some categories!
[/wpv-conditional]
Note: Please replace "category-slug" with the actual slug of your taxonomy and "123" with the actual ID of the role model post, created in step 1.
As a result, the first conditional block's content will only show for a post, which has all categories and the second one will show for a post without all categories.
I hope this helps and please let me know if you need any further assistance around this.