用于创建描述公共状态和行为的新对象的模板。不要被CSS CLASSES混淆。请改用[css]。
我是第一次在C#中使用覆盖方法,我认为我对基础知识有很好的了解。但是,我的方法有些复杂,方法中的某些调用方法。
示例代码: struct S { char数据[5]; int a; }; 在Microsoft Visual Studio中运行“运行代码分析”时,它警告以初始化所有变量。 现在我知道你...
我希望在一个语句中声明多个C ++朋友类,如下所示,只是为了整理代码。原因是,在我的实际应用中,将有三到四个朋友的课程,所以这会很混乱...
我知道我的两个日期是平等的,因为我可以使用访问者方法来获取一天,月和年,然后将其全部打印成一个日期。当我将两个日期打印为字符串时,...
方法如果是同一日期,则应返回false,但一个方法在长期显示,另一个处于简短显示中,即“ 1990年1月1日”和“ 01/01/1990”,应返回false值(如果通过
在Oracle教程中,它读到: “要访问字段,您可以使用对对象的命名引用,例如在上一个示例中,也可以使用任何返回对象引用的表达式。” gi ...
我正在使用一个特定的模式,该模式经常出现在我的一个程序中,我看不出我是在做不良的代码体系结构,还是这是一件好事。 llet的想象我们有一个
我喜欢每个文件有一个公共类的Java公约,即使有时有充分的理由将多个公共类放入一个文件中。就我而言,我有其他
Wordpress自定义Walker li id to liclass
我目前使用WordPress自定义Walker来自定义我的导航。 它目前生成此导航: 当我单击test2时,它将将Current_Page_Item类应用于IT。 所有功能都很好,但是我也想在页脚中使用相同的导航。 如果我这样做,那么由于LI ID,我会遇到验证错误。 我如何将Li ID更改为Li类? 这里是我的自定义助行器: class My_Walker extends Walker_Nav_Menu { function start_el(&$output, $item, $depth, $args) { global $wp_query; $indent = ( $depth ) ? str_repeat( "\t", $depth ) : ''; $class_names = $value = ''; $classes = empty( $item->classes ) ? array() : (array) $item->classes; $current_indicators = array('current_page_item'); $newClasses = array(); foreach($classes as $el){ //check if it's indicating the current page, otherwise we don't need the class if (in_array($el, $current_indicators)){ array_push($newClasses, $el); } } $class_names = join( ' ', apply_filters( 'nav_menu_css_class', array_filter( $newClasses), $item ) ); if($class_names!='') $class_names = ' class="'. esc_attr( $class_names ) . '"'; $output .= $indent . '<li id="menu-item-'. $item->ID . '"' . $value . $class_names .'>'; $attributes = ! empty( $item->attr_title ) ? ' title="' . esc_attr( $item->attr_title ) .'"' : ''; $attributes .= ! empty( $item->target ) ? ' target="' . esc_attr( $item->target ) .'"' : ''; $attributes .= ! empty( $item->xfn ) ? ' rel="' . esc_attr( $item->xfn ) .'"' : ''; $attributes .= ! empty( $item->url ) ? ' href="' . esc_attr( $item->url ) .'"' : ''; if($depth != 0) { //children stuff, maybe you'd like to store the submenu's somewhere? } $item_output = $args->before; $item_output .= '<a'. $attributes .'>'; $item_output .= $args->link_before .apply_filters( 'the_title', $item->title, $item->ID ); $item_output .= '</a>'; $item_output .= $args->after; $output .= apply_filters( 'walker_nav_menu_start_el', $item_output, $item, $depth, $args ); } } 在您还没有弄清楚的情况下,这是您应该做的: replace$newClasses = array();with: $newClasses = array( 'menu-item-'. $item->ID ); 替换以下行: $output .= $indent . '<li id="menu-item-'. $item->ID . '"' . $value . $class_names .'>'; : $output .= $indent . '<li' . $value . $class_names .'>';