我正在研究如何从wp_list_categories. 目前显示:
<a href="http://www.oddpandadesign.co.uk/shaun/cat-band/drummer/" title="View all posts filed under Drummer">Drummer</a>
但我希望只获得类别名称,而没有链接。那也是
Drummer
.
获取类别的完整代码:
<?php //Set Variable URL for ALL catefory
$alllink = get_post_type_archive_link( \'opd-band\' ); ?>
<?php //Category Display for Custom Post type - Video
$customPostTaxonomies = get_object_taxonomies(\'opd-band\');
if(count($customPostTaxonomies) > 0)
{
foreach($customPostTaxonomies as $tax)
{
$args = array(
\'orderby\' => \'name\',
\'show_count\' => 0,
\'pad_counts\' => 0,
\'hierarchical\' => 1,
\'taxonomy\' => $tax,
\'title_li\' => \'\',
\'data-filter\' => \'\',
\'echo\' => 0,
);
echo \'Categories: <ul id="opd-filters" class="tags-button">\';
echo \'<li><a href="#" data-filter="*">All</a>\';
echo str_replace( \'<br />\', \'\', wp_list_categories( $args ) );
echo \'</ul>\';
}
} ?>
最合适的回答,由SO网友:s_ha_dum 整理而成
自定义类别查询器应该满足您的需要。
class My_Cat_Walker extends Walker_Category {
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 );
$output .= \'<li>\'.$cat_name.\'</li>\';
}
}
$args = array(
\'orderby\' => \'name\',
\'show_count\' => 0,
\'hierarchical\' => 1,
\'taxonomy\' => $tax,
\'title_li\' => \'\',
\'data-filter\' => \'\',
\'hide_empty\' => false,
\'walker\' => new My_Cat_Walker
);
echo \'<ul>\';
wp_list_categories($args);
echo \'</ul>\';
如果你看看
source for the parent walker, 您会注意到
start_el()
method 比这个做了更多的工作。我不知道你需要这个助行器有多复杂。你在上面看到的是一个非常简单的版本。