我是Wordpress的初学者,所以如果你们中的任何人能以正确的方式推动我,我将不胜感激。无论如何,让我苦恼的是wp\\u list\\u类别(和类似的函数)如何产生许多不必要的类和我不需要的东西。
我试着基于walker\\u类别创建自己的walker类,我似乎已经开始工作了。作为一个类,我所需要的只是当它是当前类别时出现一个“当前”类,但当它不是时,我根本不希望出现任何类。
然而,出于某种原因,我得到了一个额外的分类名称类。我已经查看了我的walker class a无数次,但似乎看不到分类名称应该存储在$class中的位置。我也看过最初的Walker课程,但没能从中得到什么。
请帮忙?:)
class Meow_Walker extends Walker_Category {
var $tree_type = \'category\';
var $db_fields = array (\'parent\' => \'parent\', \'id\' => \'term_id\');
function start_lvl( &$output, $depth = 0, $args = array() ) {
if ( \'list\' != $args[\'style\'] )
return;
$indent = str_repeat("\\t", $depth);
$output .= "$indent<ul class=\'children\'>\\n";
}
function end_lvl( &$output, $depth = 0, $args = array() ) {
if ( \'list\' != $args[\'style\'] )
return;
$indent = str_repeat("\\t", $depth);
$output .= "$indent</ul>\\n";
}
function start_el( &$output, $category, $depth = 0, $args = array(), $id = 0 ) {
extract($args);
$cat_name = esc_attr( $category->name );
$cat_name = apply_filters( \'list_cats\', $cat_name, $category );
$link = \'<a href="\' . esc_url( get_term_link($category) ) . \'"\';
$link .= \'>\';
$link .= $cat_name . \'</a>\';
if ( !empty($feed_image) || !empty($feed) ) {
$link .= \' \';
if ( empty($feed_image) )
$link .= \'(\';
$link .= \'<a href="\' . esc_url( get_term_feed_link( $category->term_id, $category->taxonomy, $feed_type ) ) . \'"\';
$link .= \'>\';
if ( empty($feed_image) )
$link .= $name;
else
$link .= "<img src=\'$feed_image\'$alt$title" . \' />\';
$link .= \'</a>\';
if ( empty($feed_image) )
$link .= \')\';
}
if ( !empty($show_count) )
$link .= \' (\' . intval($category->count) . \')\';
if ( \'list\' == $args[\'style\'] ) {
$output .= "\\t<li";
if ( !empty($current_category) ) {
$_current_category = get_term( $current_category, $category->taxonomy );
if ( $category->term_id == $current_category )
$class .= \'current\';
elseif ( $category->term_id == $_current_category->parent )
$class .= \'current-parent\';
}
$output .= \' class="\' . $class . \'"\';
$output .= ">$link\\n";
} else {
$output .= "\\t$link<br />\\n";
}
}
function end_el( &$output, $page, $depth = 0, $args = array() ) {
if ( \'list\' != $args[\'style\'] )
return;
$output .= "</li>\\n";
}
}
Edit: 我找到了一个解决方法,但我仍然想知道$class的分类名称是从哪里来的。。。