Opened 2 years ago

Last modified 8 weeks ago

#16075 assigned enhancement

Add Post Type Archives support in Nav Menus

Reported by: matzipan 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)

16075_fase1.patch (11.3 KB) - added by raulillana 2 years ago.
only post type archives implemented in fase1
16075.diff (4.0 KB) - added by aaroncampbell 2 years ago.
16075-just-filter.diff (795 bytes) - added by aaroncampbell 2 years ago.
16075.2.diff (3.7 KB) - added by aaroncampbell 2 years ago.
16075.2-refresh.diff (3.5 KB) - added by DrewAPicture 5 months ago.
16075.3.diff (3.5 KB) - added by DrewAPicture 4 months ago.
post_parent
16075.4.diff (3.5 KB) - added by DrewAPicture 3 months ago.
Refresh
16075.5.diff (5.9 KB) - added by ericlewis 2 months ago.
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.

Download all attachments as: .zip

Change History (62)

  • Cc matzipan added

comment:2 in reply to: ↑ description   matzipan2 years ago

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

  • Milestone changed from Awaiting Review to Future Release
  • Type changed from feature request to enhancement

There might be a duplicate of this ticket somewhere.

  • Cc johnbillion@… added
  • Keywords nav menus post type archive registered entry removed
  • Cc raulillana added
  • 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.

Woking on this actually, dealing with the walker.

Someone more on this?

  • Keywords has-patch dev-feedback needs-testing added

comment:9   dd322 years ago

  • Keywords needs-patch removed

What's the go with the foreach loop in wp_nav_menu_post_type_archives_meta_box()?

Oops! Testing purposes only. Correcting and re-uploading in a bit.

only post type archives implemented in fase1

  • 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
  • Cc johnbillion@… removed
  • Cc johnbillion@… added

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?

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   mau2 years ago

  • Cc ngomau@… added

I have no objection to that filter.

  • 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.

In [17951]:

Add a per-post-type nav menu items filter for plugin control. props aaroncampbell. see #16075

  • 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.

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   aaroncampbell2 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).

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)

Last edited 5 months ago by aaroncampbell (previous) (diff)

That's fantastic. Thanks for doing this!

comment:25 follow-up: ↓ 29   aaroncampbell2 years ago

The plugin is in the wp.org repository now: Custom Post Type Archives in Nav Menus

Kudos! Works like a charm. :)

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.

  • 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   raulillana21 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   aaroncampbell21 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?

  • Cc info@… added
  • Cc maor@… added

+1 for getting this into core.

  • Cc travis@… added

I agree. +1 for getting this into core.

  • Cc aaroncampbell added
  • Cc jkudish added
  • Cc ben@… added
  • Cc marco@… added
  • Cc rfair404 added

comment:41 follow-up: ↓ 42   rfair4045 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   aaroncampbell5 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

  • Cc xoodrew@… added
  • Keywords needs-refresh added
  • Keywords needs-refresh removed
  • Keywords 3.6-menus added
  • Milestone changed from Future Release to 3.6

post_parent

16075.3.diff fixes a notice generated for hierarchical post types.

Last edited 3 months ago by DrewAPicture (previous) (diff)
  • Keywords needs-testing added

tested the .3 patch -- looks good and works as expected for me.

Refresh

  • Keywords needs-testing removed
  • 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.
  • 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.

  • Milestone changed from Future Release to Awaiting Review
  • 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.

  • Cc wordpress@… added
Note: See TracTickets for help on using tickets.