WordPress.org

Ready to get started?Download WordPress

Ideas

A way to activate menu trail

  1. lenart
    Member

    12345

    Under some circumstances it would be great if you could force WordPress to highlight a certain menu trail (down to a specified menu item) and let it do the magic as it usually does (assigning current- classes to appropriate menu items).

    Assuming custom menu structure below I imagine I could do this like so:

    Page 1
     |- Item 1.1
       |- Item 1.1.1
     |- Item 1.2
    Page 2
    Page 3
    
    <?php
     wp_nav_menu(
        array('active_trail_item' => wp_get_menu_item_by_id( 21 ))
     );
    ?>

    Besides wp_get_menu_item_by_id users could also find such function useful wp_get_menu_item_by_name.

    Posted: 2 years ago #
  2. Ipstenu (Mika Epstein)
    Half-Elf Support Rogue & Mod

    Look up 'breadcrumbs' - You can do this.

    Posted: 2 years ago #
  3. lenart
    Member

    12345

    @Ipstenu: I guess I didn't make myself clear enough. I understand breadcrumbs can be installed and shown via a plugin (e.g. Breadcrumbs NavXT). But when you have a slightly more complex menu structure as shown above it would be great if a user could tell wordpress where in the menu it should think it is.

    Consider this schema:

    Page 1
      |- Page 2 (custom template that lists category archives)
         |- Category 1
         |- Page 3

    In the example above when one opens up a a single post from Category 1 the navigation should assign .current-something to Page 1, Page 2 and Category 1 as well; which it does not now. As far as I know WP is not aware which post belongs to which part of menu so a manual activation is needed.

    Have I made things any clearer? Thanks for being patient with me :)

    Posted: 2 years ago #
  4. Ipstenu (Mika Epstein)
    Half-Elf Support Rogue & Mod

    The problem is associating the items back up the chain. Breadcrubs work well for posts and pages (and categories) when organized traditionally. When you're crossing over like your example, there's no way to magically detect that Page 2 belongs with Cat 1, so there's no way to code that in WP without using meta data, I suspect.

    This would be something to work out as a plugin first.

    (FYI - My theme handles breadcrumbs just fine, no plugins needed)

    Posted: 2 years ago #
  5. lenart
    Member

    12345

    @Ipstenu: I hope I'll get the hang of WP soon and be able to write a decent plugin that does what I asked for above.

    Meanwhile, if someone else finds this idea worth including in the WP core, I'll be here to help with additional use cases.

    Posted: 2 years ago #

RSS feed for this topic

Reply

You must log in to post.

  • Rating

    12345
    1 Vote
  • Status

    This is plugin territory