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
版权声明:本文标题:php - current-post-parent for custom post type 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745639887a2667788.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论