• Resolved gbucken

    (@gbucken)


    Hi,

    I would like to know if it’s possible to display the subcategories when we see an article?

    For example, Let’s say that I’ve got a menu with 2 categories.
    On my homepage, my menu will look like this:
    – Category 1
    – Category 2

    If I click on the First Category and then on the Sub_cat 1, my menu will look like this:
    – Category 1
    * Sub_cat 1
    * Sub_cat 2
    * Sub_cat 3
    – Category 2

    But when I see an article/post that is in the Sub_cat 1 (of the Category 1); my menu look like if I was on the homepage instead of showing the three Sub_cat of the first category…

    Thanks a lot in advance,
    Gaetan

    http://wordpress.org/extend/plugins/advanced-menu-widget/

Viewing 10 replies - 1 through 10 (of 10 total)
  • Also having the same problem.

    <u>My set-up looks like this:</u>
    – Main menu has only top level items
    – Advanced menu widget shows the next level and down of the selected parent item (Achieved with “Only related sub-items” and “Starting depth: 1”)

    I have “Include parents” and “Post related parents” checked also

    The main menu has:
    – Catagory 1
    and the advanced menu show’s the following children when Category 1 is selected:
    – Sub category 1
    – Sub category 2

    But viewing posts in either Sub category doesn’t render the advanced menu at all

    I need to do the same thing. I have a parent category called Newsroom, and two sub categories called News and Press Releases. When I look at the category page for either News or Press releases, the Advanced menu widget shows the correct menu. However, if I view a post within either sub category, the Advanced menu widget shows an empty menu.

    I have a fix that isn’t pretty but it did the job for my site…

    in the following file
    advanced-menu-widget/advanced-menu-widget.php

    look for the following block of code near the bottom of the Walk method

    // descend only on current tree
    $descend_test = array_intersect( $current_element_markers, $e->classes );
    
    if ( empty( $descend_test ) && !$this->direct_path )  {
        unset ( $children_elements );
    }

    comment out the unset line so it looks like this

    // descend only on current tree
    $descend_test = array_intersect( $current_element_markers, $e->classes );
    
    if ( empty( $descend_test ) && !$this->direct_path )  {
        //unset ( $children_elements );
    }

    [Please post code & markup between backticks or use the code button. Your posted code may now have been permanently damaged by the forum’s parser.]

    I always try and avoid modifying plugins so I can get updates.

    I was able to solve it a different way, though it’s not very pretty either. I used the built-in Custom Menu widget and using CSS hid the items I didn’t want to show. The Custom Menu widget shows the entire menu hierarchy, so you can select items that aren’t related to the current page/post and hide them via CSS. In the end it produces the same results as Advanced Menu Widget, but will also show the proper items on a post.

    I’m not thrilled that there is HTML rendering for all the menu items that I’m hiding, but this will work well enough for now.

    Thread Starter gbucken

    (@gbucken)

    Thank you both for your answers.

    Spencermefford, the problem with your fix, is that it’s not really beneficial for seo if I’m not mistaken..

    As for harveyharveyharvey, I think you put twice the same code. Can you please show in which part of the file should I add your fix plz?

    Thanks a lot!

    Sorry for not making it clear.

    I posted a larger block of code to help you find it. You only need to comment out one line from that block…

    // descend only on current tree
    $descend_test = array_intersect( $current_element_markers, $e->classes );

    if ( empty( $descend_test ) && !$this->direct_path ) {
    //unset ( $children_elements );
    }

    You’ll find the block of code near the bottom of the function called walk. Again only need to comment out the one “unset” line as show in bold above

    Think I also had to change the “Show hierarchy:” setting to “Only strictly related sub-items”

    Thread Starter gbucken

    (@gbucken)

    This is working well, thanks a lot!

    If I do this, the entire menu disappears… anyone else?

    It may be because of your menu configuration

    Have you got “Only related sub-items”, “Include parents” and “Post related parents” checked?

Viewing 10 replies - 1 through 10 (of 10 total)
  • The topic ‘How to display submenus related to articles/posts?’ is closed to new replies.