如何在 WordPress 中显示所有可用的自定义 post 类别?
How to display all available custom post categories in WordPress?
如何在不列出项目的情况下在主屏幕上显示自定义 post 类型的所有类别。
我已经创建了自定义 post 类型及其类别,现在我需要在我的主页上显示所有类别作为指向每个类别页面的链接。有人可以帮忙吗?
$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;
$cat_args = array(
'taxonomy' => 'your-custom-post', // your custom post type
);
$custom_terms = get_categories($cat_args);
echo print_r($custom_terms);
您现在可以使用了get_categories
这是一个代码示例:
<?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
}
?>
记住在此处填写您注册时的分类名称'Your Taxonomy Name'
例如product_cat
、blog_cat
等
希望对您有所帮助。
<?php
$terms = get_terms( 'taxonamy_name', array(
'orderby' => 'count',
'hide_empty' => 0
) );
foreach($terms as $term)
{
echo $term->name;
}?>
</ul>
</div>
如何在不列出项目的情况下在主屏幕上显示自定义 post 类型的所有类别。
我已经创建了自定义 post 类型及其类别,现在我需要在我的主页上显示所有类别作为指向每个类别页面的链接。有人可以帮忙吗?
$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;
$cat_args = array(
'taxonomy' => 'your-custom-post', // your custom post type
);
$custom_terms = get_categories($cat_args);
echo print_r($custom_terms);
您现在可以使用了get_categories
这是一个代码示例:
<?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
}
?>
记住在此处填写您注册时的分类名称'Your Taxonomy Name'
例如product_cat
、blog_cat
等
希望对您有所帮助。
<?php
$terms = get_terms( 'taxonamy_name', array(
'orderby' => 'count',
'hide_empty' => 0
) );
foreach($terms as $term)
{
echo $term->name;
}?>
</ul>
</div>