如何在 Wordpress 中显示父类别列表(带链接) [英] How to Display a List of Parent Categories (with Links) in Wordpress
本文介绍了如何在 Wordpress 中显示父类别列表(带链接)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
所以我在 在 wordpress 中显示所有父类别的列表时遇到了这个困境.
So i have this dilemma on displaying a list of all the parent categories in wordpress.
我正在使用以下代码:
<ul><li><?php wp_list_categories('orderby=order&title_li=&depth=1'); ?></li></ul>
不幸的是,这不起作用,我真的不知道为什么.发生的情况是它只显示了唯一的一个类别.
Unfortunately, this doesn't work which I really don't know why. what happens is it only shows the only ONE category.
如果有人对此提供帮助,我将不胜感激.
I would appreciate anyone's help on this please.
推荐答案
试试这个.我之前测试过
Try this one. I have tested before
<?php
$args = array(
'orderby' => 'name',
'hierarchical' => 1,
'taxonomy' => 'category',
'hide_empty' => 0,
'parent' => 0,
);
$categories = get_categories($args);
foreach($categories as $category) {
echo '<a href="' . get_category_link($category->cat_ID) . '" title="' . $category->name . '">' . $category->name . '</a><br>';
}
?>
或者试试这个.让我知道哪个更好.
<?php wp_list_cats('optionall=0&depth=1&list=0&exclude=1&children=0&hide_empty=0'); ?`>
这篇关于如何在 Wordpress 中显示父类别列表(带链接)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文