Skip Navigation

[Resolved] Display subcategory name ONCE in a view within a view

This support ticket is created 3 years, 5 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.

No supporters are available to work today on Toolset forum. Feel free to create tickets and we will handle it as soon as we are online. Thank you for your understanding.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Karachi (GMT+05:00)

This topic contains 2 replies, has 2 voices.

Last updated by Waqar 3 years, 5 months ago.

Assisted by: Waqar.

Author
Posts
#1850193
Screen Shot 2020-11-19 at 12.33.05 PM.png
Screen Shot 2020-11-19 at 12.32.38 PM.png
Screen Shot 2020-11-19 at 12.32.03 PM.png
Screen Shot 2020-11-19 at 12.11.40 PM.png

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

#1850489

Waqar
Supporter

Languages: English (English )

Timezone: Asia/Karachi (GMT+05:00)

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

#1853209

Waqar
Supporter

Languages: English (English )

Timezone: Asia/Karachi (GMT+05:00)

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.

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