How to show a list of only categories (exclude subcategories)

I have a list where you show me the categories, but I would like you not to show me the subcategories, only the categori

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 badges
Add a comment  | 

1 Answer 1

Reset to default 1
$args = array(
  'orderby' => 'name',
  'order' => 'ASC',
  'parent' => 0
);
$categories = get_categories($args);

May this will help you. Refer this link

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745405084a4626279.html

相关推荐

  • How to show a list of only categories (exclude subcategories)

    I have a list where you show me the categories, but I would like you not to show me the subcategories, only the categori

    5小时前
    40

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信