显示*的wordpress类别

问题描述:

我有以下的在我的WordPress的模板,我想改变它的码位,所以它只显示*类别,而不是所有类别:显示*的wordpress类别

<?php 
/** 
* Generate list of EDD categories to browse 
*/ 

if ($categories) { ?> 

    <div class="search-cats"> 
     <div class="search-cat-text"> 
      <?php _e('Or browse by category: ', 'checkout'); ?> 
     </div> 
     <nav> 
     <?php 
      /** 
      * Generate list of EDD category links 
      */ 
      foreach ($categories as $category) { 
       $link = get_term_link($category, 'download_category'); 


       echo '<a href="' . esc_url($link) . '" rel="tag">' . $category->name . '</a>'; 
      } 
     ?> 
     </nav> 
    </div> 
<?php } ?> 

灿谁来帮帮我?

点是父=> 0

<?php 
    /** 
    * Generate list of EDD categories to browse 
    */ 
    $args = array(
     'orderby' => 'name', 
     'taxonomy' => 'download_category', 
     'hide_empty' => 0, 
     'parent' => 0 
    );  
    $categories = get_categories($args); 
+0

谢谢,完美的作品。 – Teege

通过使用get_categories()使用这样的代码,你应该尝试:

$args = array(
    'orderby' => 'name', 
    'parent' => 0 
); 

父 (整数)获取的直接子这个词(只有明确的父母是这个值的词)。 如果通过0,则只返回*条款。默认为空字符串。

了解更多:http://codex.wordpress.org/Function_Reference/get_categories#Get_only_top_level_categories