admin管理员组

文章数量:1434900

I have 2 archive pages on my site. First "News" is for standard wordpress posts. Second "Projects" is for my custom post type. When I go to specific post from "News" archive then my menu position "News" should be active. But it doesn't. So I do small refactor in my nav walker (I'm using Bulmascores_Nav_Walker by Seyong Cho). So I made something like this

     if (in_array('current-menu-item', $classes) || in_array('current-post-parent', $classes)  ) {
        $class_names .= 'is-active';
    }

And it working like it should. Problems starts when I want to do the same for my custom post type. I made print_r for classes and I can't see 'current-post-parent'. Below full code for this class

    public function getLinkButton($item)
{
    $url         = $item->url ?? '';
    $classes     = empty($item->classes) ? array() : (array) $item->classes;
    print_r($classes);
    $class_names = '';

    if (in_array('current-menu-item', $classes) || in_array('current-post-parent', $classes)  ) {
        $class_names .= 'is-active';
    }

    $button = sprintf("<a href='%s' class='navbar-item %s'>%s</a>", $url, $class_names, $item->title);

    return $button;
}

Array for active custom post type item

Array
(
    [0] => 
    [1] => menu-item
    [2] => menu-item-type-post_type_archive
    [3] => menu-item-object-projekty
)

it should contain current-post-parent but I don't know how to achieve this. So, anyone could help me, please?

本文标签: phpcurrentpostparent for custom post type