我想在我的 wordpress 链接列表中呈现一些额外的 css 类,特别是 id 喜欢将链接类别呈现为 css 类,例如:
link : http://www.foobar.com/
gategories : friends, colleagues
name : Foo Bar
当前呈现为:
<a href="http://www.foobar.com/" target="_blank">Foo Bar</a>
但我希望它呈现为:
<a href="http://www.foobar.com/" target="_blank" class="friends colleagues">Foo Bar</a>
我知道您使用以下函数来构建链接列表,但我无法弄清楚如何修改它来满足我的需要:
function wp_list_bookmarks($args = '') {
$defaults = array(
'orderby' => 'name', 'order' => 'ASC',
'limit' => -1, 'category' => '', 'exclude_category' => '',
'category_name' => '', 'hide_invisible' => 1,
'show_updated' => 0, 'echo' => 1,
'categorize' => 1, 'title_li' => __('Bookmarks'),
'title_before' => '<h2>', 'title_after' => '</h2>',
'category_orderby' => 'name', 'category_order' => 'ASC',
'class' => 'linkcat', 'category_before' => '<li id="%id" class="%class">',
'category_after' => '</li>'
);
$r = wp_parse_args( $args, $defaults );
extract( $r, EXTR_SKIP );
$output = '';
if(1) {
//output one single list using title_li for the title
$bookmarks = get_bookmarks($r);
if ( !empty($bookmarks) ) {
if ( !empty( $title_li ) ){
$output .= str_replace(array('%id', '%class'), array("linkcat-$category", $class), $category_before);
$output .= "$title_before$title_li$title_after\n\t<ul class=\"xoxo blogroll $category\">\n";
$output .= _walk_bookmarks($bookmarks, $r);
$output .= "\n\t</ul>\n$category_after\n";
} else {
$output .= _walk_bookmarks($bookmarks, $r);
}
}
}
$output = apply_filters( 'wp_list_bookmarks', $output );
if ( !$echo )
return $output;
echo $output;
}
?>
谢谢!