我有两个问题涉及'类别' Wordpress部分。
我正在使用此代码在我的Wordpress网站中显示类别。
HTML
<?php
$args = array(
'show_option_all' => 'ALL',
'title_li' => ''
);
?>
<h3 class="category-list"><?php wp_list_categories($args); ?></h3>
<h2> ... </h2>
我想用图标/图形替换类别Name(来自Fontawesome,我正在使用bootstrap框架),并在&lt; h2&gt;我想展示slug但我不知道如何完成这个
答案 0 :(得分:0)
add_shortcode('custom_categories', 'custom_categories_function');
function custom_categories_function() {
$upload_dir = wp_upload_dir();
$args = array(
'hide_empty' => FALSE,
'taxonomy' => 'ads-category',
'orderby' => 'name',
'show_count' => 1,
'pad_counts' => 1,
'hierarchical' => FALSE,
'parent' => 0,
'title_li' => '',
'show_option_none' => '',
'echo' => 0
);
$all_categories = get_categories($args);
$html = "<ul>";
foreach ($all_categories as $categories_item) {
$html .= '<li class="'.$categories_item->slug.'"><img src="'. $upload_dir['baseurl'].'/ads_cat_icons/'.$categories_item->slug.'.png"> <a href="' . get_term_link($categories_item) . '">' . $categories_item->name . '</a> (' . $categories_item->count . ')';
$html .= '<ul>';
$args['parent'] = $categories_item->cat_ID;
$html .= wp_list_categories($args);
$html .= '</ul></li>';
}
$html .= "</ul>";
return $html;
}