我正在尝试在wp\\U list\\U页面创建的列表上设置交替类。
目前,我已经扩展了Walker\\u page类,更新了start\\u el函数,如下所示:
class Sidebar_walker extends Walker_page {
var $alternate = \'background_1\';
function start_el( &$output, $page, $depth, $args, $current_page = 0 ) {
if ( $depth )
$indent = str_repeat("\\t", $depth);
else
$indent = \'\';
extract($args, EXTR_SKIP);
$css_class = array(\'page_item\', \'page-item-\'.$page->ID);
$alternate = ($alternate != \'background_1\') ? \'background_1\' : \'background_2\';
$css_class[] = $alternate;
if ( !empty($current_page) ) {
$_current_page = get_post( $current_page );
if ( in_array( $page->ID, $_current_page->ancestors ) )
$css_class[] = \'current_page_ancestor\';
if ( $page->ID == $current_page )
$css_class[] = \'current_page_item\';
elseif ( $_current_page && $page->ID == $_current_page->post_parent )
$css_class[] = \'current_page_parent\';
} elseif ( $page->ID == get_option(\'page_for_posts\') ) {
$css_class[] = \'current_page_parent\';
}
$css_class = implode( \' \', apply_filters( \'page_css_class\', $css_class, $page, $depth, $args, $current_page ) );
$output .= $indent . \'<li class="\' . $css_class . \'"><a href="\' . get_permalink($page->ID) . \'">\' . $link_before . apply_filters( \'the_title\', $page->post_title, $page->ID ) . $link_after . \'</a>\';
if ( !empty($show_date) ) {
if ( \'modified\' == $show_date )
$time = $page->post_modified;
else
$time = $page->post_date;
$output .= " " . mysql2date($date_format, $time);
}
}
}
只有background\\u 1正在打印。如何获取$alternate以实际更新。