Tell us what you are trying to do?
I'm using a view within a view to display all posts under a specific category. It is mostly working except that the subcategory name repeats.
These are my categories:
SELF HELP
- WP
- - Word Press basic tips
- HARDWARE
- - Hardware PC
- - Hardware Mac
- EMAIL
- - PC
- - Mac
I have 3 views -
1. TaxonomyViewSelfHelp - a taxonomy view that selects categories under the "Self Help" Category
2. TaxonomyViewChildSelfHelp - a taxonomy view that selects categories based on the parent view and then shows the category title in the loop.
3. TaxonomyViewGrandchildSelfHelp - a post view that selects posts who's category is set by parent Taxonomy view and displays category name and a link to the post in the loop.
The result is close but the "grandchild" category name repeats.
I get this:
- WP
- - Word Press basic tips
* post name and link
- HARDWARE
- - Hardware PC
* post name and link
- - Hardware Mac
* post name and link
- - Hardware Mac
* post name and link
- EMAIL
- - PC
* post name and link
- - Mac
* post name and link
(note that the category "Hardware Mac" is repeated. In this test I have only one post in every category, except "Mac Hardware" where I have 2 posts)
Any help that you could offer would be greatly appreciated.
Thank you!
What is the link to your site?
hidden link
Hi,
Thank you for contacting us and I'd be happy to assist.
This will require some custom CSS or JS code trick and to suggest the best way forward, I'll need to see exactly how these nested views are set up in the backend.
Can you please share temporary admin login details in reply to this message?
Note: Your next reply will be private and please make a complete backup copy, before sharing the access details.
regards,
Waqar
Thank you for sharing the admin access.
To remove the duplicated sub-category titles, you can follow these steps:
1. In your view "TaxonomyViewGrandchildSelfHelp", you can enclose sub-category title, in a span tag, with current term's slug and a special class for example "special-title":
<span class="[wpv-post-taxonomy type='category' format='slug'] special-title">--[wpv-post-taxonomy type="category" format="name"]<br></span>
2. Next, in the same view's "JS editor", you can include the following custom JS code:
jQuery( document ).ready(function() {
var arr = [];
jQuery('span.special-title').each(function(i, obj) {
var currentClass = jQuery(this).attr('class');
if(jQuery.inArray(currentClass, arr) !== -1) {
jQuery(this).css("display", "none");
}
else{
arr[i++] = currentClass;
}
});
});
The above code cycles through all the available span tags with class "special-title" and stores the unique class names in an array and hides it, if its a repeated one.