sourcecode

목록에서 범주 제외 - Wordpress

codebag 2023. 9. 25. 22:37
반응형

목록에서 범주 제외 - Wordpress

다음 목록에 범주를 표시하지 않도록 하려고 합니다.

<?php
    $categories = get_categories( 'orderby=id&exclude=1,'. getOption('promo-categorie', false) );
    foreach( $categories as $category ) :
        $active = ( !is_home() && get_query_var( 'cat' ) == $category->term_id )? ' style="color: ' . getOption($category->category_nicename . '-color', false) . '"' : '';
        $catLink = ( get_query_var( 'cat' ) == $category->term_id ) ? get_bloginfo( 'wpurl' ) : get_category_link( $category->term_id );
?>
  <a class="nav-links" href="<?php echo ( get_query_var( 'sort' ) == 'list' )? add_query_arg( array( 'sort' => 'list' ), $catLink ) : $catLink ?>" <?php echo $active; ?>><?php echo $category->name; ?></a>
<?php
    endforeach;
?>

저는 PHP를 사용하는 완전한 신입이지만, 제가 알기로는 "프로모카테고리"가 제외되고 있습니다.그 외에 다른 카테고리는 제외하고 싶습니다.

어떤 도움이라도 주시면 감사하겠습니다.

배열에서 id를 제외할 수 있습니다.제외 매개 변수에 여러 ID를 전달할 수 있습니다.

$args = array(  
    'hide_empty'               => 1,    
    'exclude'                  =>array(1,2,3) // desire id
); 

$categories = get_categories($args );

언급URL : https://stackoverflow.com/questions/26667240/exclude-category-from-list-wordpress

반응형