admin管理员组文章数量:1130349
Does anyone know how to display the wp_list_categories() on a div instead of the li?
I basically want to wrap main categories and its children in a bootstrap column.
$args = array(
'taxonomy' => 'product_category',
'hide_empty' => 0,
'orderby' => 'name',
'order' => 'ASC',
'show_count' => 0,
'use_desc_for_title' => 0,
'title_li' => 0
);
wp_list_categories($args);
Does anyone know how to display the wp_list_categories() on a div instead of the li?
I basically want to wrap main categories and its children in a bootstrap column.
$args = array(
'taxonomy' => 'product_category',
'hide_empty' => 0,
'orderby' => 'name',
'order' => 'ASC',
'show_count' => 0,
'use_desc_for_title' => 0,
'title_li' => 0
);
wp_list_categories($args);
Share
Improve this question
edited Jul 30, 2015 at 22:36
tfrommen
9,2317 gold badges40 silver badges59 bronze badges
asked Jul 30, 2015 at 21:42
HugoHugo
311 gold badge1 silver badge2 bronze badges
2 Answers
Reset to default 5You can specify the style argument as something other than the default (which is list) and it won't wrap the output in a <li>. You can then wrap it in a <div> yourself.
Combine it with the echo argument if you need to check that the list isn't empty. Example:
$args = array(
'taxonomy' => 'product_category',
'hide_empty' => 0,
'orderby' => 'name',
'order' => 'ASC',
'show_count' => 0,
'use_desc_for_title' => 0,
'title_li' => 0,
'style' => '',
'echo' => false,
);
$categories = wp_list_categories($args);
if ( $categories ) {
printf( '<div class="col">%s</div>', $categories );
}
Please add two new argument into your $args array.
1) Style with none value. See the markup section for more. 2) echo with 0(False).
Now call and store the result into $categories variable and print it via printf().
Final code like:
$args = array(
'taxonomy' => 'product_category',
'hide_empty' => 0,
'orderby' => 'name',
'order' => 'ASC',
'show_count' => 0,
'use_desc_for_title' => 0,
'title_li' => 0,
'style' => 'none',
'echo' => 0,
);
$categories = wp_list_categories($args);
if ( $categories ) {
printf( '<div>%s</div>', $categories );
}
In aditional, you can use if ( !preg_match( '/No\scategories/i', $cats ) ) If the displayed text reads "No categories".
P.S. If this stuff helps you please leave me a comment and support :)
Does anyone know how to display the wp_list_categories() on a div instead of the li?
I basically want to wrap main categories and its children in a bootstrap column.
$args = array(
'taxonomy' => 'product_category',
'hide_empty' => 0,
'orderby' => 'name',
'order' => 'ASC',
'show_count' => 0,
'use_desc_for_title' => 0,
'title_li' => 0
);
wp_list_categories($args);
Does anyone know how to display the wp_list_categories() on a div instead of the li?
I basically want to wrap main categories and its children in a bootstrap column.
$args = array(
'taxonomy' => 'product_category',
'hide_empty' => 0,
'orderby' => 'name',
'order' => 'ASC',
'show_count' => 0,
'use_desc_for_title' => 0,
'title_li' => 0
);
wp_list_categories($args);
Share
Improve this question
edited Jul 30, 2015 at 22:36
tfrommen
9,2317 gold badges40 silver badges59 bronze badges
asked Jul 30, 2015 at 21:42
HugoHugo
311 gold badge1 silver badge2 bronze badges
2 Answers
Reset to default 5You can specify the style argument as something other than the default (which is list) and it won't wrap the output in a <li>. You can then wrap it in a <div> yourself.
Combine it with the echo argument if you need to check that the list isn't empty. Example:
$args = array(
'taxonomy' => 'product_category',
'hide_empty' => 0,
'orderby' => 'name',
'order' => 'ASC',
'show_count' => 0,
'use_desc_for_title' => 0,
'title_li' => 0,
'style' => '',
'echo' => false,
);
$categories = wp_list_categories($args);
if ( $categories ) {
printf( '<div class="col">%s</div>', $categories );
}
Please add two new argument into your $args array.
1) Style with none value. See the markup section for more. 2) echo with 0(False).
Now call and store the result into $categories variable and print it via printf().
Final code like:
$args = array(
'taxonomy' => 'product_category',
'hide_empty' => 0,
'orderby' => 'name',
'order' => 'ASC',
'show_count' => 0,
'use_desc_for_title' => 0,
'title_li' => 0,
'style' => 'none',
'echo' => 0,
);
$categories = wp_list_categories($args);
if ( $categories ) {
printf( '<div>%s</div>', $categories );
}
In aditional, you can use if ( !preg_match( '/No\scategories/i', $cats ) ) If the displayed text reads "No categories".
P.S. If this stuff helps you please leave me a comment and support :)
本文标签: categoriesHow to display wplistcategories on div instead of li
版权声明:本文标题:categories - How to display wp_list_categories on div instead of li? 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:https://it.en369.cn/questions/1749199153a2331503.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。


发表评论