admin管理员组文章数量:1425860
I have a list where you show me the categories, but I would like you not to show me the subcategories, only the categories
$term_id = get_categories();
if (function_exists('get_wp_term_image'))
{
$meta_image = get_wp_term_image($term_id);
//It will give category/term image url
}
$categories = get_categories();
foreach($categories as $category) {
?>
<article>
<div class="poster">
<a href="<?php echo get_category_link($category->term_id); ?>">
<?php echo '<img src="'.get_wp_term_image($category->term_id).'">' ?>
</div>
<div class="orbit_starts">
<h2><?php echo $category->name ?></h2></a>
</div>
</article>
How would you exclude all subcategories?
Thank you
I have a list where you show me the categories, but I would like you not to show me the subcategories, only the categories
$term_id = get_categories();
if (function_exists('get_wp_term_image'))
{
$meta_image = get_wp_term_image($term_id);
//It will give category/term image url
}
$categories = get_categories();
foreach($categories as $category) {
?>
<article>
<div class="poster">
<a href="<?php echo get_category_link($category->term_id); ?>">
<?php echo '<img src="'.get_wp_term_image($category->term_id).'">' ?>
</div>
<div class="orbit_starts">
<h2><?php echo $category->name ?></h2></a>
</div>
</article>
How would you exclude all subcategories?
Thank you
Share Improve this question asked Jun 13, 2019 at 13:41 juanjuan 12 bronze badges1 Answer
Reset to default 1$args = array(
'orderby' => 'name',
'order' => 'ASC',
'parent' => 0
);
$categories = get_categories($args);
May this will help you. Refer this link
本文标签: How to show a list of only categories (exclude subcategories)
版权声明:本文标题:How to show a list of only categories (exclude subcategories) 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745405083a2657215.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论