Skip Navigation

[Resolved] Use current taxonomy View term archive URL in nested post View

This thread is resolved. Here is a description of the problem and solution.

Problem: I have a View of Taxonomy terms. In the loop of that View, I have a nested View of posts. I would like to access the archive URL of the current taxonomy term inside the loop of the View of posts, so I can build a link back to the term archive page.

Solution: Use a View attribute to pass the current archive term URL into the nested View of posts, then use the wpv-attribute shortcode to access that attribute.
Nested View shortcode in the taxonomy View's loop:

[wpv-view name="chapters-within-each-chapter" classpart="[wpv-taxonomy-url]"]

Access the URL inside the nested View's loop:

<a href="[wpv-attribute name='classpart']#[wpv-post-slug]">...</a>

Relevant Documentation:
https://toolset.com/documentation/user-guides/passing-arguments-to-views
https://toolset.com/documentation/user-guides/views-shortcodes/#vf-309292

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

Sun Mon Tue Wed Thu Fri Sat
8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 - -
13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 - -

Supporter timezone: America/New_York (GMT-04:00)

Tagged: 

This topic contains 6 replies, has 2 voices.

Last updated by liatG 6 years, 2 months ago.

Assisted by: Christian Cox.

Author
Posts
#1131458
Show single classes link not working.png

Hi there, this is for Christian Cox, please! 😀

Hi Christian, I'm opening a ticket based on https://toolset.com/forums/topic/only-call-one-taxonomy-term-for-use-in-a-view-when-a-post-has-several/ to see if you can help me. I know you work today and Waqar doesn't, and I wanted to specifically request your help anyway.

The code Waqar gave me didn't work for me. I added it as a Custom code snippet in my Toolset settings. I wasn't sure whether to also register this as a third-party shortcode, but, trying it both ways, it didn't work. I added the shortcode to my view inside the link (see screenshot - you can see how the link shows up in the URL preview in the left-hand corner) and also outside the link just to view the results. It just prints the shortcode, it doesn't return any URL.

Do you think you can help me write something that will return the single URL?

ALSO - I need to be able to specify WHICH URL. The first one isn't necessarily the one I need to call. We can maybe use the [get-current-slug] shortcode to specify which of the taxonomy terms to link to... or some other way to identify which URL to use. Speaking in plain English, I need to call the class part that is part of the class the user is currently looking at.

I'm not sure what the smartest way to do this is. I just know I need to do using logic instead of manually separating out these classes, because I tried duplicating all the chapters to create totally separate classes, and it's not feasible. I will end up with 3x and 4x duplicate content because these chapters are re-used in several classes, and it results in several hundred added chapters.

Thank you so much for your help. This is my last step in finishing my membership site and launching it to my clients.

Thank you,
Liat

#1132064

Okay so let me make sure I understand what you want to do. Let's look at this page:
hidden link

Please tell me the full URLs each of these menu items should link to:
What Is Toe-Up?
What Is Two-At-A-Time?
How To Use This Course
Toe-Up Sock Pattern
Choose Your Materials

I'll take a look and make sure I understand, then we can talk about a solution.

#1132072

What Is Toe-Up? - hidden link
What is Two-at-a-Time - hidden link
How To Use This Course - hidden link
Toe-Up Sock Pattern - hidden link
Choose Your Materials - hidden link

Thank you!

#1132106

Oh, okay I don't think any special conditional logic is necessary. Just pass the taxonomy archive URL from the parent View into the nested View as an attribute "classpart": (hidden link)

[wpv-view name="chapters-within-each-chapter" classpart="[wpv-taxonomy-url]"]

Then access that "classpart" attribute in the nested View to build the link URL:
(hidden link)

<a href="[wpv-attribute name='classpart']#[wpv-post-slug]">

Check it now and let me know if I've misunderstood.

#1132135

You are so incredible!!!! You solved my problem in a way that I didn't even know was possible! You made everything more simple. Now ALL my classes work the way they should, regardless of whether the chapters are shared between multiple classes. You have helped me more than anyone else in the history of the Internet.

I'm ONLY leaving this open, and I'm sorry to do you like this, to ask for your help or advice regarding another ticket I couldn't solve by myself: https://toolset.com/forums/topic/only-load-images-inside-bootstrap-panel-on-click-to-reduce-page-load-time/. I know this isn't part of your scope of work at Toolset, but even if I could pay you separately, is there some way you could advise me on this ticket? I don't know anyone who knows code and I don't know how to follow Luo's advice by myself, although it seems incredibly straightforward.

#1132736

Supporters are contractually forbidden from taking on freelance work, but I can offer some advice. If the lists of images are displayed with Views, you can use Infinite Scrolling on all the Views (https://toolset.com/documentation/user-guides/infinite-scrolling-in-views/). This will load only a few images in each View at first, then as the User scrolls to the bottom of the list more results will be added with AJAX. That's probably the easiest alternative that doesn't require custom code, and can dramatically reduce the initial load time for a page with many images.

Another option is a separate Lazy Load plugin. There are several out there, and I don't know how well any of them work, but if you have time to experiment you may find one that works well on your site.

#1133721

Thank you Christian! You totally solved this problem for me (about the taxonomy terms). Thank you also for your advice about infinite scroll. It's not quite working for me, but if I have more questions I'll open a separate ticket. Thank you thank you!