Php 如何在WordPress中显示所有可用的自定义帖子类别?
如何在主屏幕上显示自定义帖子类型的所有类别,而不列出项目 我已经创建了自定义帖子类型及其类别,现在我需要将主页上的所有类别显示为每个类别页面的链接。有人能帮忙吗?Php 如何在WordPress中显示所有可用的自定义帖子类别?,php,wordpress,custom-post-type,categories,Php,Wordpress,Custom Post Type,Categories,如何在主屏幕上显示自定义帖子类型的所有类别,而不列出项目 我已经创建了自定义帖子类型及其类别,现在我需要将主页上的所有类别显示为每个类别页面的链接。有人能帮忙吗?$args=array('post\u type'=>'post','posts\u per\u page'=>10); $args = array( 'post_type' => 'post', 'posts_per_page' => 10 ); $loop = new WP_Query( $args ); while (
$args=array('post\u type'=>'post','posts\u per\u page'=>10);
$args = array( 'post_type' => 'post', 'posts_per_page' => 10 );
$loop = new WP_Query( $args );
while ( $loop->have_posts() ) : $loop->the_post();
the_title();
echo '<div class="entry-content">';
the_content();
echo '</div>';
endwhile;
$loop=新的WP_查询($args);
而($loop->have_posts()):$loop->the_post();
_title();
回声';
_内容();
回声';
结束时;
您现在可以使用
下面是一个代码示例:
<?php
$args = array(
'taxonomy' => 'Your Taxonomy Name'
'hide_empty' => 0,
'orderby' => 'name'
);
$cats = get_categories($args);
foreach($cats as $cat) {
?>
<a href="<?php echo get_category_link($cat->slug); ?>">
<?php echo $cat->name; ?>
</a>
<?php
}
?>
记住在注册时写下你的分类名称,在这里“你的分类名称”
e、 g.产品目录
,博客目录
等
希望这对您有所帮助。
<?php
$terms = get_terms( 'taxonamy_name', array(
'orderby' => 'count',
'hide_empty' => 0
) );
foreach($terms as $term)
{
echo $term->name;
}?>
</ul>
</div>
这将列出自定义posttype的项目,而不是其类别。请查看。这是错误的。分类法参数不需要post类型。请参见此处->
<?php
$terms = get_terms( 'taxonamy_name', array(
'orderby' => 'count',
'hide_empty' => 0
) );
foreach($terms as $term)
{
echo $term->name;
}?>
</ul>
</div>