admin管理员组

文章数量:1389772

I have a custom taxonomy, "Events". I want to add the object for this taxonomy type as a Menu item (Appearance > Menus).

I don't mean I want to add a term of Events. I mean the taxonomy itself.

For a post type (say, my custom post type "Viewpoints") it is possible to add this as a Menu item (in Appearance > Menus, just go to my post type on the left-hand side of the menu builder, open it up, go "View All" and choose the top-most item, "Viewpoint Archives")...

But, for a taxonomy archive, there is no equivalent "[Taxonomy] Archives", nothing to select...

I know I can add a Custom Link to any front-end destination. Indeed, my "Events" are all output on a theme page page-events.php. But this is not a real pointer to the taxonomy object.

Is this because WordPress knows no such thing as a taxonomy archive index page? My understanding is, that is not a thing. Hence, I wrote page-events.php as a page template, and the code content spits out the relevant queries to list the terms.

Does anyone know of a workaround?

I am considering adding an ACF field to the menu items, because ACF's "ACF Taxonomy Selector Field" add-on would allow me to point to the real taxonomy object.

I have a custom taxonomy, "Events". I want to add the object for this taxonomy type as a Menu item (Appearance > Menus).

I don't mean I want to add a term of Events. I mean the taxonomy itself.

For a post type (say, my custom post type "Viewpoints") it is possible to add this as a Menu item (in Appearance > Menus, just go to my post type on the left-hand side of the menu builder, open it up, go "View All" and choose the top-most item, "Viewpoint Archives")...

But, for a taxonomy archive, there is no equivalent "[Taxonomy] Archives", nothing to select...

I know I can add a Custom Link to any front-end destination. Indeed, my "Events" are all output on a theme page page-events.php. But this is not a real pointer to the taxonomy object.

Is this because WordPress knows no such thing as a taxonomy archive index page? My understanding is, that is not a thing. Hence, I wrote page-events.php as a page template, and the code content spits out the relevant queries to list the terms.

Does anyone know of a workaround?

I am considering adding an ACF field to the menu items, because ACF's "ACF Taxonomy Selector Field" add-on would allow me to point to the real taxonomy object.

Share Improve this question asked Mar 14, 2020 at 21:22 Robert AndrewsRobert Andrews 9881 gold badge19 silver badges42 bronze badges 1
  • When you say you want a pointer to the taxonomy object what do you mean? Are you referring to individual terms? If there is no taxonomy archive index page then what are you expecting to show in that menu? Pages on the frontend are either singular posts, or archives of posts, there's no such thing as an archive of terms or an archive of users – Tom J Nowell Commented Mar 14, 2020 at 21:34
Add a comment  | 

1 Answer 1

Reset to default 0

Is this because WordPress knows no such thing as a taxonomy archive index page? My understanding is, that is not a thing. Hence, I wrote page-events.php as a page template, and the code content spits out the relevant queries to list the terms.

Yes. All frontend pages in WP are post queries. WP looks at the query to figure out which template to load, and the main loop displays the posts.

If the query is for a single post, then it's a singular query, e.g. a blog post, a page, etc. If multiple posts are shown, it's an archive.

As a result, WP has no concept of an archive of users, or an archive of terms. The reason you don't see the page for the taxonomy itself is because there isn't one. you can test this out by taking example/taxonomy/term and removing /term, you'll get a 404 or redirected elsewhere.

Likewise, if we look at how rewrite rules work, URLs match on to regular expressions, that turn the URL into a list of query variables for a WP_Query object. The entire URL parsing stack is built to fuel post queries.

Having said that, you could build such a page, but you would need to create a rewrite rule for each taxonomy root page, and add query variables, then look for those and load the template manually, it's not for the faint of heart. To add to that, these "virtual pages" won't show up in the menu creation UI.

Keep in mind that in the next year or two, the menu creation process is earmarked for significant change and overhaul as part of the full site editing project, especially with the recent introduction of nav menu blocks ( written in 2020 )

本文标签: How to add a taxonomy type in Menus