WordPress.org

Make WordPress Core

Opened 3 years ago

Last modified 5 weeks ago

#16075 assigned enhancement

Add Post Type Archives support in Nav Menus

Reported by: matzipan Owned by:
Milestone: Awaiting Review Priority: normal
Severity: normal Version: 3.1
Component: Menus Keywords: has-patch ui-feedback
Focuses: Cc:

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 (9)

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

Download all attachments as: .zip

Change History (71)

comment:1 matzipan3 years ago

  • Cc matzipan added

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

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

comment:3 nacin3 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 johnbillion3 years ago

  • Cc johnbillion@… added
  • Keywords nav menus post type archive registered entry removed

comment:5 raulillana3 years ago

  • Cc raulillana added

comment:6 travisnorthcutt3 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 raulillana3 years ago

Woking on this actually, dealing with the walker.

Someone more on this?

comment:8 raulillana3 years ago

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

comment:9 dd323 years ago

  • Keywords needs-patch removed

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

comment:10 raulillana3 years ago

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

raulillana3 years ago

only post type archives implemented in fase1

comment:11 raulillana3 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 johnbillion3 years ago

  • Cc johnbillion@… removed

comment:13 johnbillion3 years ago

  • Cc johnbillion@… added

aaroncampbell3 years ago

comment:14 aaroncampbell3 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?

comment:15 aaroncampbell3 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 mau3 years ago

  • Cc ngomau@… added

comment:17 markjaquith3 years ago

I have no objection to that filter.

comment:18 aaroncampbell3 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 markjaquith3 years ago

In [17951]:

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

aaroncampbell3 years ago

comment:20 aaroncampbell3 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: travisnorthcutt3 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 aaroncampbell3 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 aaroncampbell3 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)

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

comment:24 travisnorthcutt3 years ago

That's fantastic. Thanks for doing this!

comment:25 follow-up: aaroncampbell3 years ago

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

comment:26 raulillana3 years ago

Kudos! Works like a charm. :)

comment:27 WraithKenny3 years 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 WraithKenny3 years 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: raulillana3 years 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 aaroncampbell3 years 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.

comment:31 travisnorthcutt2 years ago

  • Keywords 3.3-early removed

Any chance of this getting into core for 3.4?

comment:32 toscho2 years ago

  • Cc info@… added

comment:33 maorb2 years ago

  • Cc maor@… added

+1 for getting this into core.

comment:34 wpsmith23 months ago

  • Cc travis@… added

comment:35 sscovil21 months ago

I agree. +1 for getting this into core.

comment:36 aaroncampbell21 months ago

  • Cc aaroncampbell added

comment:37 jkudish16 months ago

  • Cc jkudish added

comment:38 husobj16 months ago

  • Cc ben@… added

comment:39 Marco_Teethgrinder15 months ago

  • Cc marco@… added

comment:40 rfair40415 months ago

  • Cc rfair404 added

comment:41 follow-up: rfair40415 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 aaroncampbell15 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 DrewAPicture15 months ago

  • Cc xoodrew@… added
  • Keywords needs-refresh added

comment:44 DrewAPicture15 months ago

  • Keywords needs-refresh removed

comment:45 DrewAPicture15 months ago

  • Keywords 3.6-menus added
  • Milestone changed from Future Release to 3.6

DrewAPicture15 months ago

post_parent

comment:46 DrewAPicture15 months ago

16075.3.diff fixes a notice generated for hierarchical post types. Also added a missing Codex reference for the 'items_archive' label in register_post_type().

Version 0, edited 15 months ago by DrewAPicture (next)

comment:47 DrewAPicture15 months ago

  • Keywords needs-testing added

comment:48 sabreuse15 months ago

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

DrewAPicture14 months ago

Refresh

comment:49 DrewAPicture14 months ago

  • Keywords needs-testing removed

comment:50 Frank Klein14 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 DrewAPicture14 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

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

comment:52 DrewAPicture13 months ago

  • Milestone changed from Future Release to Awaiting Review

comment:53 ericlewis13 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 emzo13 months ago

  • Cc wordpress@… added

comment:55 mfields11 months ago

  • Cc michael@… added

comment:56 mtekk10 months ago

  • Cc mtekkmonkey@… added

comment:57 alexvorn29 months ago

  • Cc alexvornoffice@… added
  • Severity changed from normal to major

comment:58 aaroncampbell9 months ago

  • Severity changed from major to normal

comment:59 c3mdigital8 months ago

  • Keywords needs-refresh added

comment:60 Frank Klein3 months ago

  • Cc contact@… added

paulwilde3 months ago

comment:61 paulwilde3 months ago

  • Keywords needs-refresh removed

Refreshed ericlewis' patch to work with trunk.

comment:62 helen5 weeks ago

#27396 was marked as a duplicate.

Note: See TracTickets for help on using tickets.