【发布时间】:2015-12-18 16:20:06
【问题描述】:
在此页面上:http://realtor.kirkdahle.com/resources-test/ 我有许多用于自定义帖子类型“资源”的类别和子类别。我目前正在努力让侧边栏显示类别和子类别以及显示所有帖子的主体。
所有帖子都在子类别中,按主要类别组织。如果至少没有一篇帖子同时检查主类别和子类别,则主类别或子类别的列表中不会显示任何内容。这是我的代码:
<?php
// gets all categories
$taxonomies = array(
'resource-cat'
);
$taxonomy_name = 'resource-cat';
$args = array(
'orderby' => 'name',
'order' => 'ASC',
'hide_empty' => true,
'exclude' => array(),
'exclude_tree' => array(),
'include' => array(),
'number' => '',
'fields' => 'all',
'slug' => '',
'parent' => '',
'hierarchical' => false,
'child_of' => 0,
'childless' => false,
'get' => '',
'name__like' => '',
'description__like' => '',
'pad_counts' => false,
'offset' => '',
'search' => '',
'cache_domain' => 'core'
);
$terms = get_terms($taxonomies, $args);
echo '<ul id="top-cats">';
foreach ($terms as $term) {
if(!$term->parent)
echo '<li class="filter_bold"><a href="'.get_term_link( $term ).'">'.$term->name.'</a></li>';
$termchildren = get_term_children( $term->term_id, $taxonomy_name );
echo '<ul>';
foreach ( $termchildren as $child ) {
$subterm = get_term_by( 'id', $child, $taxonomy_name );
if($subterm->count != 0)
echo '<li><a href="' . get_term_link( $child, $taxonomy_name ) . '">' . $subterm->name . '</a></li>';
}
echo '</ul>';
}
echo '</ul>';
?>
任何关于如何调整它的建议将不胜感激。
【问题讨论】:
-
您是否尝试过使用
offset => 0进行查询?
标签: php wordpress categories