我试图在函数中使用以下代码。php以显示带有类别的菜单(实际上是自定义分类法)。我只是想让它在当前页面上显示活动状态。我做错了什么?
我还看到$category = get_category($mycatid);
行不填充$category
变量
<?php
class walker_archives extends Walker_Nav_Menu
{
public function start_el( &$output, $item, $depth, $args )
{
$attributes = \'\';
! empty ( $item->attr_title )
and $item->attr_title !== $item->title
and $attributes .= \' title="\' . esc_attr( $item->attr_title ) .\'"\';
! empty ( $item->url )
and $attributes .= \'href="\' . esc_attr( $item->url ) .\'"\';
$attributes = trim( $attributes );
$title = apply_filters( \'the_title\', $item->title, $item->ID );
$item_output = "$args->before<a $attributes>$args->link_before$title</a>"
. "$args->link_after$args->after";
$mycatid = $item->object_id;
$category = get_category($mycatid);
$mycatslug = $category->slug;
$classes = empty( $item->classes ) ? array() : (array) $item->classes;
$class_names .= in_array("current_page_item",$item->classes) ? \' active\' : \'\';
$class_names = \' class="staysexy\'. esc_attr( $class_names );
$output .= $indent . \'
<li id="nav-menu-item-\'. $item->ID . \'" class="genre-\'. $mycatslug . \'">\';
$output .= apply_filters(
\'walker_nav_menu_start_el\'
, $item_output
, $item
, $depth
, $args
);
}
public function start_lvl( &$output )
{
$output .= \'<ul class="sub-menu">\';
}
public function end_lvl( &$output )
{
$output .= \'</ul>\';
}
function end_el( &$output )
{
$output .= \'</li>\';
}
}?>