Skip Navigation

[Resolved] How to (properly) create a page for a (top level) taxonomy?

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

Problem:

A user asked about the best approach to create different archives for the multi-level hierarchal taxonomy terms.

Solution:

Shared some suggestions along with the code example for the different archive assignments.

Relevant Documentation:

n/a

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

Author
Posts
#2318863

Tell us what you are trying to do?
___________________________
For a directory style website.

I want to create a taxonomy for a particular service, for example lets say "Laundromats Near Me", then the taxonomy terms will be individual states and city sub terms.

(I'll then do this multiple times for different services, like another one for example "Hair Salons Near Me" and then taxonomy terms of the states and sub terms for cities)

I want to have one main view/archive page for "Laundromats Near Me", which I can add breadcrumbs to the taxonomy term pages,

for example,
Home > Laundromats Near Me > California

This works fine, but, taxonomy's themselves, like "Laundromats Near Me", don't get an archive page that can be linked to in the breadcrumb as example above.

I want to have this top level taxonomy page to then help navigate/link down to the different states & cities, and this gives a nice accurate URL as well for the states, for example, /laundromats-near-me/california.
__________________________

It seems like I can achieve this by creating the taxonomy first, "Laundromats Near Me", and then going back to my WordPress pages, and creating a page with the same URL as the taxonomy.

New page > URL: /laundromats-near-me

Then I can use Toolset Views I think? (which I haven't used yet, only experience in the archive editor), use Toolset Views, to add a view of all locations (locations is my custom post type), that fall under any of the states or city taxonomy terms within the "Laundromats Near Me" taxonomy.

This is because I want an explorer/directory page for all Laundromats, allowing the user to enter their state to view the locations etc.

Then all I need to do, is custom code my breadcrumbs for the taxonomy term pages (the state pages, ie california), so that the taxonomy > Laundromats Near Me > links up to the URL /laundromats-near-me page that I created with Toolset Views.

________________________

Is this the best method to achieve this?

Or is there a taxonomy page builder or something which I am missing?

It seems like WordPress/Toolset only creates archive pages for the taxonomy terms and not the taxonomy itself, so I think if I want to achieve this URL structure, then this is the way to do it?

Please let me know if you have any advice on how to go about this the RIGHT way.

Thanks!
G
________________________

Is there any documentation that you are following?

The only support tickets I can find for similar questions are when I do a Google search for this question + Toolset, but all of them that pop up show 404 page not found.

Where did all those support ticket pages go anyways, looks like a lot of them would be helpful for me haha.

#2319217

Hi,

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

Your observation is correct and WordPress supports archive pages for taxonomy terms but not a main taxonomy archive page for all the terms.

In light of that, your planned approach of using a regular page with a post view seems like a good option.

One possible alternative can be adding a hierarchal custom taxonomy "Laundromats" and in it, you can add a parent term "Laundromats Near Me" so that all the other state and city terms are its children:

- Laundromats Near Me
-- State 1
--- City 1 State 1
--- City 2 State 1
-- State 2
--- City 1 State 2
--- City 2 State 2
.............................

With this structure, the grandparent "Laundromats Near Me" term will have an archive page of its own. A downside of this would be that the taxonomy slug "laundromat" will be included in the URL of the term archive pages.

Examples:
{yourwebsite.com}/laundromat/laundromats-near-me/
{yourwebsite.com}/laundromat/laundromats-near-me/state/
{yourwebsite.com}/laundromat/laundromats-near-me/state/city

As for the support forum threads showing 404, We're in the process of removing the old support forums threads, which include information that is no longer applicable or outdated.
( The support forum threads which are two years older are archived, and only supporters and users who started them will have access to them. Forum threads older than 5 years have been removed )

We'll recommend using our forum search ( https://toolset.com/forums/forum/professional-support/ ) instead of Google to search for the support forum topics that you're looking for. In case the information that you're looking for is not available, you're welcome to start a new ticket and we'll be happy to assist you accordingly.

regards,
Waqar

#2321135

Thanks Waqar, great comments.

Couple of things.

When I create a new taxonomy, does it really matter if I use the exact same name for the singular and plural versions which it asks for?

The nomenclature I'm using kind of just makes itself the same terminology for both plural and singular. Looks like I can save it this way but is there any issue with that?

Another question,

It doesn't look like I need to download the legacy views plugin for this?

All these different plugins make it a bit confusing..

It looks like I can just insert the views block on to whatever page I like and it should work..

Thanks

#2322799

Thanks for writing back and glad that my message helped.

I did some research online and couldn't find any issue or drawback of having the same singular and plural labels for the taxonomy. However, I'll recommend using different labels, whenever possible, just to be safe.

Your observation is correct and the Toolset Blocks is a newer version of the Toolset Views plugin and includes all its features. When the Toolset Blocks plugin is active, you don't need the Toolset Views plugin.

#2323483

The next issues I'm having related to this topic.

1.

When selecting which taxonomies to apply this view to, when I click the drop down, it doesn't show me a complete list.

If I click apply to all terms, then it assigns archive pages to all of the cities as well as the states.

While this could be a good thing, I have a City search filter on the state page, and because it's assigned to all states>cities, then the city filter shows up on those pages for the cities also.

I tried seeing if I could use a conditional block to only display this search filter on the state archive page but couldn't figure out a way to do this either. I dont think a way exists with the conditional blocks.

Ideally I would just be able to create an archive page design, and assign it only to the first level of taxonomy terms, and not the sub term level.

How can I achieve this?

Otherwise I can type each individual state into the taxonomy selector to find and select it, 50 times, and then times the 3 categories I have, but this seems like a very messy way to do it.

Especially when I extend that to the city term level because I have over 400 cities in the data base, times 3 categories...

2.

How can I copy the archive page code into the next category properly?

This is so that I can make the couple minor tweaks etc. like for example with breadcrumbs and title headers and be finished the design as designing the page once took many hours. (and still I didn't figure out how to make the page work for city sub terms)

#2324113

There is no direct/straightforward method available to overcome the challenges mentioned in both these points, so this will require some workaround and possibly code customizations.

Can you please share temporary admin login details, so that I can see how these taxonomy items and archives are set up in the admin area?

I'll be in a better position to guide you around the next steps accordingly.

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

#2324337

what do you need to know, I would prefer not to share login details as I'm testing this all on my live website.

Currently the taxonomy items are set up exactly how I described above.

It seems like I just need to manually select each taxonomy state term each time, 150 times.

Unless there is a way to put in a custom code snippet somewhere that will only apply that archive page design to the top level taxonomy terms and not sub terms.

Then I'll need to create another archive page, and select the taxonomy sub terms for each city I want it to apply to.

It looks like I was able to copy paste a couple containers from one archive to the next so that helped speed things up. And I see there is some kind of module plugin which I may use in the future.

#2324891

Thanks for writing back.

During testing on my website, I was able to control this dynamic assignment of WordPress Archives for different level terms using the "wpv_filter_force_wordpress_archive":
https://toolset.com/documentation/programmer-reference/views-filters/#wpv_filter_force_wordpress_archive

Here are the steps:

1. I added a custom taxonomy with slug 'laundromats-near-me', in which state and city terms were added in a hierarchal structure.
( screenshot: hidden link )

2. Next, I created two separate WordPress Archives, "Archive for States" (ID: 41) for the state level terms and "Archive for Cities" (ID: 46) for the city level terms.
( screenshot: hidden link )

Note: it doesn't matter which of these two is assigned for the taxonomy term archive pages, as we'll be controlling the assignment through the custom code anyway.

3. Next, I needed a custom function attached to the filter "wpv_filter_force_wordpress_archive" that works only of the archives for the 'laundromats-near-me' taxonomy terms and if the current term has a parent, assign the city level archive and if not, assign the state level archive:


add_filter( 'wpv_filter_force_wordpress_archive', 'wpv_filter_force_wordpress_archive_tax_1', 30, 2 );
function wpv_filter_force_wordpress_archive_tax_1( $wpa_assigned, $wpa_loop ) {

	// slug of the target taxonomy
	$target_tax_1_slug = 'laundromats-near-me';
	// ID of the WP Archive created for the state level terms
	$target_tax_1_state_archive_id = '41';
	// ID of the WP Archive created for the city level terms
	$target_tax_1_city_archive_id = '46';

	// check if the archive is for the target taxonomy term
	if ( $wpa_loop == 'view_taxonomy_loop_'.$target_tax_1_slug ) {
		// get information about the term whose archive page is being viewed
		$term = get_queried_object();
		// check if the current term has some parent
		if($term->parent > 0) {
			// if parent term exists it means it is a city term and assign the archive for the city
			$wpa_assigned = $target_tax_city_archive_id;
		}
		else
		{
			// if no parent term exists it means it is a state term and assign the archive for the state
			$wpa_assigned = $target_tax_state_archive_id;
		}
	}

	return $wpa_assigned;
}

The above code snippet can be included through either Toolset's custom code feature ( ref: https://toolset.com/documentation/adding-custom-code/using-toolset-to-add-custom-code/ ) or through the active theme's "functions.php" file.

Make sure to replace the taxonomy slug and WordPress Archive IDs, with the ones used on your website.

For other taxonomies, you can repeat these steps of creating two separate archives and adding a similar custom function.

Note: The custom code examples from our forum are shared to get you started in the right direction. You're welcome to adjust them as needed and for more personalized customization assistance, you can consider hiring a professional from our list of recommended contractors:
https://toolset.com/contractors/

#2325697

Dude, amazing.

Works like a dang charm.

Very powerful.

One note for anyone getting help from this topic in the future, there was one single little typo in the code.

The archive assignment lines of code,

$wpa_assigned = $target_tax_city_archive_id;
$wpa_assigned = $target_tax_state_archive_id;

they were initialized with a 1 in them originally, and this needs to be added in.
$wpa_assigned = $target_tax_1_city_archive_id;
$wpa_assigned = $target_tax_1_state_archive_id;

Then it works amazing!!

Dope code.

Thanks Waqar!