簡體   English   中英

從輸出中排除特定類別 ID

[英]Exclude specific category id's from being output

我的網站上有以下代碼,用於輸出“下載”帖子類型的類別列表。 我希望從輸出中排除某些類別,我該怎么做?

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

if ( $categories ) {
  ?>
<div class="search-cats">
  <div class="search-cat-text">
    <?php _e( '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 } ?>

您要查找的參數中的參數是exclude請參閱https://developer.wordpress.org/reference/classes/wp_term_query/__construct/以獲取有關可用於此類查詢的參數的詳細信息。

$args = array(
  'orderby' => 'name',
  'hierarchical' => 1,
  'style' => 'none',
  'taxonomy' => 'download_category',
  'hide_empty' => 0,
  'depth' => 1,
  'title_li' => '',
  'exclude' => 24,21 /* Array or comma/space-separated string of term IDs 
                        to exclude. If $include is non-empty, $exclude is
                        ignored. Default empty array. */
);
$categories = get_categories( $args );

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM