Skip Navigation

[Resolved] How to use content templates for extra path information

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.

Our next available supporter will start replying to tickets in about 2.27 hours from now. 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 5 replies, has 2 voices.

Last updated by Waqar 1 year, 3 months ago.

Assisted by: Waqar.

Author
Posts
#2633641

Hi, I would like to add "subpages" for a content template.
Basically there will be a tabbed navigation on the content template. When one of the headers is clicked, I want to redirect users to another page where the related information is displayed.

This is a basic version of how it will look like: hidden link

Every tab will contain data from the database so I don't want to load everything once the page loads. That's the reason I am thinking about redirecting the users to a different "page" when they click the link.

example:
myurl.com/company/company-slug -> this is the main page for the company
myurl.com/company/company-slug/reviews -> this is the page where I display the company reviews
myurl.com/company/company-slug/events -> this is the page where I display the company's active events

What is the best way for me to achieve this?

Thanks in advance

#2633907

Hi,

Thank you for contacting us and I'd be happy to assist.

The most logical approach that won't require too much code customization or workarounds would be:

1. You can make the 'company' custom post type hierarchal so that each post in it, can have sub-posts.

For example:

- Company A
-- Company A Reviews
-- Company A Events

- Company B
-- Company B Reviews
-- Company B Events

- Company C
-- Company C Reviews
-- Company C Events

....

This will give you the URL/sub-page structure that you're looking for.

2. For the content templates, you can create a separate content template for each hierarchal level too:

a). CT for Company
b). CT for Company - Reviews
c). CT for Company - Events

The 'CT for Company' will be the main content template that will be assigned to this 'company' post type.

For the other two, they can be forced, through a custom function attached to the 'wpv_filter_force_template' hook:
https://toolset.com/documentation/programmer-reference/views-filters/#wpv_filter_force_template

That custom function will check if the 'review' or 'event' level company post is being viewed and will override the assigned content template, accordingly.

I hope this helps and please let me know if you need further assistance.

regards,
Waqar

#2633933

Hi Waqar,

Thank you for your support. Since I have created the custom post types already and it might cause issues if I set the hierarchy now, I can try the second approach you recommended. Is there any example I can follow or use as a reference?

#2634289

Thanks for writing back.

I suggested only a single approach in my last reply and those two are the steps for it. Both will be needed for this to work.

> Since I have created the custom post types already and it might cause issues if I set the hierarchy now,
- I don't foresee any issue in changing this post type setting. But you're welcome to make a complete back-up copy of the website, just to be extra cautious.

> Is there any example I can follow or use as a reference?
- I'm afraid, I don't have a reference website or code example available for this. But you can follow the steps suggested in my last reply and then if you face any challenge, feel free to share temporary admin login details of the website.

I'll be able to guide you with the next steps accordingly.

Note: Your next reply will be private and making a complete backup copy is recommended before sharing the access details.

#2634795

Hi Waqar,

I have thousands of events created in the system. If we are to create a parent\child relationship, does that mean I need to set that relationship for all existing records? Also I have a custom relationship between companies and events, would that be absolute then?

[edit] For some reason, the information I shared here is not private and visible by everyone. So I had to edit my message to remove the login information

#2635689

Thanks for writing back.

In the approach that I suggested earlier, the 'Reviews' and 'Events' details won't be saved in the form of separate custom post types. They'll be part of the same 'Company' post type but in the form of hierarchal posts.

From what you've described, it looks like the Events are already added as a separate post type. If you'd like to keep them that way, then my suggested approach won't work.

Alternatively, you can keep the 'Reviews' and 'Events' in their separate post types, and then link them with the 'Company' post type, through one-to-many relationships:

a). Company -> Reviews
b). Company -> Events

Next, you can register custom endpoints for the 'Company' post type, for the '/reviews/' and '/events/':
https://developer.wordpress.org/reference/functions/add_rewrite_endpoint/

Here is a useful guide on the topic of registering custom URL endpoints in WordPress:
hidden link

Once these endpoints are working, you can use the 'wpv_filter_force_template' hook, to detect which endpoint is in use and then override the relevant content template, accordingly:
https://toolset.com/documentation/programmer-reference/views-filters/#wpv_filter_force_template

For more personalized assistance around custom code, you can also consider hiring a professional from our list of recommended contractors:
https://toolset.com/contractors/