Skip Navigation

[Resolved] Help setting up “term pagination” in term archive pages.

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

Problem: I am using term archives to display posts without pagination, and I would like to create Next and Previous links to paginate to another term archive page. The sort order should be determined by a custom field on the terms.

Solution:
Use Views filtered by term where the term ID is set by a shortcode attribute. Pass the current term's field value into the filter and sort by the term field value. Use the following custom shortcode to determine the current term's order.

function archive_part_num_func($atts) {
  $current_taxonomy = isset(get_queried_object()->taxonomy) ? get_queried_object()->taxonomy : null;
  if( $current_taxonomy == 'class-part' ) {
    $id = get_queried_object()->term_id;
    $partnum = types_render_termmeta( 'part-order', array('term_id'=>$id));
    return $partnum;
  }
  return;
}
add_shortcode("archive-part-num", "archive_part_num_func");

Add to the View filter like this:

<p>← Previous: [wpv-view name="class-parts-filtered-by-part-order-previous" partnum="[archive-part-num]"]</p>
<p>→ Next: [wpv-view name="class-parts-filtered-by-part-order-next" partnum="[archive-part-num]"]</p>

Register "archive-part-num" in Toolset > Settings > Front-end content > Third party shortcode arguments.

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

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

This topic contains 11 replies, has 4 voices.

Last updated by liatG 6 years, 4 months ago.

Assisted by: Christian Cox.

Author
Posts
#1096414
Current
Current
Desired Layout for Next:Previous Term Links.png
Previous:Next Navigation on Layout - First Attempt.png
Class Parts Filtered by Part Order - Previous.png
Class Parts Filtered by Part Order - Next.png
Part Orders.png

Hi there, this is for Christian Cox, please.

Hi again!
I would like help setting up "term pagination" for my term archive pages as we discussed in https://toolset.com/forums/topic/help-using-custom-taxonomies-to-create-online-tutorials-and-their-navigation/#post-1096407.

To prepare, I set up a custom number field "part order" for my custom "class part" taxonomy and set numbers 1-9 for the taxonomy terms. I set the numbers in order independent of the hierarchy levels as follows: (see Screenshot: Part Orders). I figured we could set the view to navigate to the next parent term if that's where the user is, or the next child term if that's where the user is. Let me know if you want me to set the part order numbers differently.

I then created two views of the taxonomy terms filtered by part order. See screenshots: Class Parts Filtered by Part Order - Next, and Class Parts Filtered by Part Order - Previous. I used the fake shortcode attribute "tbd" as a holding spot until you give me the right shortcode attribute(s).

I then added these view to the layout. See screenshot: Previous/Next Navigation on Layout - First Attempt. I tried to put them side by side by using 6 columns for each cell, but they ended up stacking. Obviously all the links show up right now as the filter is a fake one, but see screenshots: Current "Previous" Links and Current "Next" Links. Once we get the coding right, can you help me format the layout so that one term shows up on the left and the other shows up on the right? (as in Screenshot: Desired Layout for Next/Previous Term Links).

I think that is all I can do on my end for now, can you help me set up the shortcodes and anything else you see that I may not have done right?

Thanks!
L

#1096894

Nigel
Supporter

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

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

Hi Liat

Christian doesn't work today, his next day is Sunday.

Reply to this whether you need someone else to look into this or would like to wait for Christian.

#1096937

Hi Nigel,
I'd be willing to have anyone on the support team answer this if they can.
Thank you!
Liat

#1097138

Hi again,
I'd like to wait for Christian.
Thanks,
Liat

#1098659

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Liat,

Christian is currently on holiday today but I can re-assign this ticket to him so he can handle when he gets back.

Thanks,
Shane

#1098742

Hey Shane, Happy holiday,

Thanks, please do assign it to Christian and I'll wait till he gets back.
Same for the other tickets I have open where I mentioned him.

Have a great day and thanks for your help,
Liat

#1099615

Okay these are the next steps:
- Edit the "Previous" View and change the Order to be ordered by part number, descending, instead of term name. Then change the number displayed to be 1 instead of "No limit".
- Edit the Query Filter to be set by a shortcode attribute "partnum" instead of a URL parameter.
- Edit the "Next" View and change the Order to be ordered by part number, ascending, instead of term name. Then change the number displayed to be 1 instead of "No limit".
- Edit the Query Filter to be set by a shortcode attribute "partnum" instead of a URL parameter.
- Edit this Layout and remove the two View cells you are currently using to place the next and previous buttons. Replace those two cells with one Visual Editor cell, spanning the full width of the Layout.
- Insert the Previous View and the Next View in the Visual Editor cell using the Fields and Views button. In the popup dialog, use the left tabs to add the shortcode attribute "partnum", and for now set it to be 3.
- Test the new Layout and Views on the taxonomy archive that corresponds to part number 3. You should see the next and previous links appear, and they should be displaying links to part number 2 and part number 4.

Let me know if you get through these steps or run into trouble and I'll take a look. Next we will make the links dynamic, based on the current taxonomy archive. Then we will work on a few final touches and formatting.

#1103739
Current previous and next archive terms links.png

Hi Christian,

I set up what you described, but when I go to the Part 3 archive, the links show as in the screenshot.

#1104604

Okay the "Previous" View sorting should have been descending, that was my fault. Then the two shortcode attributes should be like this:

<p>← Previous: [wpv-view name="class-parts-filtered-by-part-order-previous" partnum="3"]</p>
<p>→ Next: [wpv-view name="class-parts-filtered-by-part-order-next" partnum="3"]</p>

Then you need a way to make that "3" dynamic so that it is automatic based on the current term archive. I added this custom shortcode to help:

function archive_part_num_func($atts) {
  $current_taxonomy = isset(get_queried_object()->taxonomy) ? get_queried_object()->taxonomy : null;
  if( $current_taxonomy == 'class-part' ) {
    $id = get_queried_object()->term_id;
	$partnum = types_render_termmeta( 'part-order', array('term_id'=>$id));
	return $partnum;
  }
  return;
}
add_shortcode("archive-part-num", "archive_part_num_func");

Now the updated shortcodes should be like this:

<p>← Previous: [wpv-view name="class-parts-filtered-by-part-order-previous" partnum="[archive-part-num]"]</p>
<p>→ Next: [wpv-view name="class-parts-filtered-by-part-order-next" partnum="[archive-part-num]"]</p>

In order for those to work, you must register "archive-part-num" in Toolset > Settings > Front-end content > Third party shortcode arguments. However, I'm getting 504 Gateway timeout errors on that page again. Do you have access to server logs? Can you see if any information is logged that can help explain these timeouts?

#1104641

Thank you so much, Christian!

I just got off the chat with my web host, and they found nothing in the server logs to explain the timeouts for that page. They did try to troubleshoot but could not get into the page despite their best efforts. They suggested I contact the plugin developers or a dedicated WordPress developer.

I'll open a separate ticket for this.

Thanks,
Liat

#1106614

Now that we have the settings page issue under control, I believe you should be able to test this solution. I'll stand by for your update.

#1107690
Final Result.png

It works perfectly! Thank you so much. I included a screenshot just to show the final result.

I used the instructions from this page: hidden link to make the formatting come out right.

This is so wonderful, it's exactly what I wanted. Thank you so much for your help/doing this all for me.

Cheers,
Liat