Opened 2 years ago
Last modified 8 weeks ago
#16075 assigned enhancement
Add Post Type Archives support in Nav Menus
| Reported by: |
|
Owned by: | |
|---|---|---|---|
| Priority: | normal | Milestone: | Awaiting Review |
| Component: | Menus | Version: | 3.1 |
| Severity: | normal | Keywords: | has-patch ui-feedback |
| Cc: | matzipan, raulillana, travis@…, johnbillion@…, ngomau@…, Ken@…, info@…, maor@…, travis@…, aaroncampbell, jkudish, ben@…, marco@…, rfair404, xoodrew@…, Frank, Klein, wordpress@… |
Description
The setup: Take a post type (be it default or custom, in my case custom)
I wish to be able to add the archive page to the menu without adding the menu entry as hardcoded link (in my case /artists/)
The problem: Adding it as hardcoded link does not bring the page up as current page in the menu when visiting the link.
Example:
http://www.blowmeup.ro/artists/ vs http://www.blowmeup.ro/crews/
Attachments (8)
Change History (62)
comment:2
in reply to:
↑ description
matzipan — 2 years ago
- Milestone changed from Awaiting Review to Future Release
- Type changed from feature request to enhancement
There might be a duplicate of this ticket somewhere.
comment:4
johnbillion — 2 years ago
- Cc johnbillion@… added
- Keywords nav menus post type archive registered entry removed
comment:5
raulillana — 2 years ago
- Cc raulillana added
comment:6
travisnorthcutt — 2 years ago
- Cc travis@… added
- Keywords needs-patch added
I wish to be able to add the archive page to the menu without adding the menu entry as hardcoded link (in my case /artists/)
Someone correct me if I'm wrong, but I believe adding the archive page to the menu as a hardcoded link (http://site.com/post-type) does apply the expected current-menu-item class. However, adding the archive page as a relative link (/post-type) does not. Semantics, I know, but worth mentioning.
That being said, I agree that there's a need for a metabox on the menu page that would allow adding custom post type archives to a menu, and would cause the appropriate classes to be added.
comment:7
raulillana — 2 years ago
Woking on this actually, dealing with the walker.
Someone more on this?
comment:8
raulillana — 2 years ago
- Keywords has-patch dev-feedback needs-testing added
- Keywords needs-patch removed
What's the go with the foreach loop in wp_nav_menu_post_type_archives_meta_box()?
comment:10
raulillana — 2 years ago
Oops! Testing purposes only. Correcting and re-uploading in a bit.
comment:11
raulillana — 2 years ago
- Keywords 3.2-early added
- Owner changed from matzipan to raulillana
- Status changed from new to assigned
- Summary changed from Post type archive registered as entry in nav menus to Add Post Type Archives support in Nav Menus
comment:12
johnbillion — 2 years ago
- Cc johnbillion@… removed
comment:13
johnbillion — 2 years ago
- Cc johnbillion@… added
aaroncampbell — 2 years ago
comment:14
aaroncampbell — 2 years ago
I accidentally opened #17463 because my search for "has_archive" on here didn't return this ticket.
The patch I just attached will make everything automatic. If a post type is added and "has_archive" then the archive link checkbox will show. You can optionally include a items_archive label to be used.
I'm wondering if we could at least add a filter to 3.2 which could allow a plugin to handle this until this fix can be added?
aaroncampbell — 2 years ago
comment:15
aaroncampbell — 2 years ago
That latest patch just adds a single filter nav_menu_items_{$post_type_name}. That's what I'd like to see make 3.2. It seems like an area that plugins should have control over but don't. Ultimately I'd like to see the filter stay in (obviously) but still see the other patch use as well to make the archive bits work automagically.
comment:16
mau — 2 years ago
- Cc ngomau@… added
comment:17
markjaquith — 2 years ago
I have no objection to that filter.
comment:18
aaroncampbell — 2 years ago
- Keywords dev-feedback needs-testing 3.2-early removed
- Milestone changed from Future Release to 3.2
Moving this to 3.2 to get the filter added.
comment:19
markjaquith — 2 years ago
In [17951]:
aaroncampbell — 2 years ago
comment:20
aaroncampbell — 2 years ago
- Keywords 3.3-early added
- Milestone changed from 3.2 to Future Release
Refreshed patch for trunk. I'm going to move this back to "future release" and try to get it into 3.3 since it would still be nice to have the "archives" option appear and work automatically.
comment:21
follow-up:
↓ 22
travisnorthcutt — 2 years ago
Would it be viable to get at least some form of this in 3.2, and expand on it for 3.3?
comment:22
in reply to:
↑ 21
aaroncampbell — 2 years ago
Replying to travisnorthcutt:
Would it be viable to get at least some form of this in 3.2, and expand on it for 3.3?
We did. We added a filter in [17951] that would let a plugin do this exact thing. I'll release the plugin before 3.2 comes out (maybe this weekend if I get time).
comment:23
aaroncampbell — 2 years ago
The plugin is currently on github: Custom Post Type Archives in Nav Menus. When it's approved I'll add it to extend as well (Custom Post Type Archives in Nav Menus)
comment:24
travisnorthcutt — 2 years ago
That's fantastic. Thanks for doing this!
comment:25
follow-up:
↓ 29
aaroncampbell — 2 years ago
The plugin is in the wp.org repository now: Custom Post Type Archives in Nav Menus
comment:26
raulillana — 2 years ago
Kudos! Works like a charm. :)
comment:27
WraithKenny — 22 months ago
It'd be nice to have _wp_menu_item_classes_by_context assign some classes (like current-item-in-archive, current-archive-ancestor or some-such label consistent with existing ones) to the archive menu item if the currently viewed item is in that archive.
comment:28
WraithKenny — 22 months ago
- Cc Ken@… added
Maybe give the archive menu item and it's menu parents the current-menu-parent and current-menu-ancestor classes? Just an idea.
comment:29
in reply to:
↑ 25
;
follow-up:
↓ 30
raulillana — 21 months ago
Replying to aaroncampbell:
The plugin is in the wp.org repository now: Custom Post Type Archives in Nav Menus
Stopped working on 3.2
Take a look, please. ;)
comment:30
in reply to:
↑ 29
aaroncampbell — 21 months ago
Replying to raulillana:
Replying to aaroncampbell:
The plugin is in the wp.org repository now: Custom Post Type Archives in Nav Menus
Stopped working on 3.2
Take a look, please. ;)
This is not the place for plugin support.
- Keywords 3.3-early removed
Any chance of this getting into core for 3.4?
comment:32
toscho — 15 months ago
- Cc info@… added
comment:34
wpsmith — 12 months ago
- Cc travis@… added
comment:35
sscovil — 11 months ago
I agree. +1 for getting this into core.
comment:36
aaroncampbell — 11 months ago
- Cc aaroncampbell added
comment:37
jkudish — 5 months ago
- Cc jkudish added
comment:38
husobj — 5 months ago
- Cc ben@… added
- Cc marco@… added
comment:40
rfair404 — 5 months ago
- Cc rfair404 added
comment:41
follow-up:
↓ 42
rfair404 — 5 months ago
Is the purpose of the filter in [17951] to allow plugin authors to control the archive title beyond the args supplied when registering the actual post type?
comment:42
in reply to:
↑ 41
aaroncampbell — 5 months ago
Replying to rfair404:
Is the purpose of the filter in [17951] to allow plugin authors to control the archive title beyond the args supplied when registering the actual post type?
Actually, I asked to have it added to allow you to add menu items to the list, but put it there so you could also edit them (bonus!). Take a look at the plugin I made using it (referenced above):
https://github.com/OpenRange/Custom-Post-Type-Archives-in-Nav-Menus/blob/master/cpt-archives-in-nav-menus.php
comment:43
DrewAPicture — 5 months ago
- Cc xoodrew@… added
- Keywords needs-refresh added
DrewAPicture — 5 months ago
comment:44
DrewAPicture — 5 months ago
- Keywords needs-refresh removed
comment:45
DrewAPicture — 4 months ago
- Keywords 3.6-menus added
- Milestone changed from Future Release to 3.6
comment:46
DrewAPicture — 4 months ago
16075.3.diff fixes a notice generated for hierarchical post types.
comment:47
DrewAPicture — 4 months ago
- Keywords needs-testing added
comment:48
sabreuse — 4 months ago
tested the .3 patch -- looks good and works as expected for me.
comment:49
DrewAPicture — 3 months ago
- Keywords needs-testing removed
comment:50
Frank Klein — 3 months ago
- Cc Frank Klein added
I tested the most recent patch, and here are the issues I ran into:
- With the permalinks settings on default, the link of the custom post type archive doesn't work, as it relies on the slug.
- After enabling a common setting for the permalinks, the link to the CPT archive worked and the menu item had the current-menu-item CSS class added to it. However on the single page of the CPT, there were no parent or ancestor classes added to the menu item.
- On the Menus screen in the admin, the link to the CPT archive is marked as "custom", it should have another label.
comment:51
DrewAPicture — 3 months ago
- Keywords 3.6-menus removed
- Milestone changed from 3.6 to Future Release
- Owner raulillana deleted
Moving this to Future Release unless somebody else wants to pick up the ball. As it stands:
- There's still outstanding issues as outlined in comment:50
- No consensus on whether these links qualify as "custom" or "page" links
- No consensus on whether these links belong in the post type meta boxes
Fixes issues brought up in comment 50. Works properly with default permalinks as well as custom. In the menus admin screen, the CPT archive is now marked as "Archive," a new menu item type. Current menu item is set when on either an archives page for the post type or a single CPT page.
comment:52
DrewAPicture — 2 months ago
- Milestone changed from Future Release to Awaiting Review
comment:53
ericlewis — 2 months ago
- Keywords ui-feedback added
This could use a glance as far as UI is concerned.
In the menu editor, the placement of "Post Archives" exclusively under the "All Posts" tab doesn't feel completely natural to me. Perhaps with some minor styling (padding, font styling) it would look like it belongs more.
comment:54
emzo — 8 weeks ago
- Cc wordpress@… added

It seems the same problem applies to taxonomies (these being added without hardcoded entry)