簡體   English   中英

排除Wordpress中的前兩個類別

[英]Excluding first two categories in Wordpress

因此,我想排除數組中的前兩個類別,我希望它是動態的,因此無論有人更改orderby還是父級,exclude參數將始終排除數組中的前兩個類別。

我已經搜索了很長時間,似乎找不到任何解決方法:(。

$args = array( 'orderby' => 'name', 'parent' => 46, 'taxonomy' => 'category', 'hide_empty' => 1, 'exclude' =>  ##first & second in array ## );

$categories = get_categories( $args );

foreach ( $categories as $category ) { 
echo '<li>
    <a href="' . get_category_link($category->term_id) . '">
        <img src="' . z_taxonomy_image_url($category->term_id) . '" />
        <div class="info">
            <div class="vert-center">
                <h4 class="note-name">' . $category->cat_name . '</h4>
                <hr>
                <p class="note-descriptor">' . $category->category_description . '</p>
            </div>
        </div>
    </a>
</li>';
} ?>

$categories = get_categories( $args );

在上面的這一行中,您持有一組類別。 [1] [2] [3] [4] [5] [6] [7] [8] [9]

因此,如果您取消設置,它應該可以在unset($categories[0]);

編輯您還將需要array_value來修復空索引

$newcat = array_values($categories);

在你的學習之前

foreach ( $categories as $category ) { 
echo '<li>
    <a href="' . get_category_link($category->term_id) . '">
        <img src="' . z_taxonomy_image_url($category->term_id) . '" />
        <div class="info">
            <div class="vert-center">
                <h4 class="note-name">' . $category->cat_name . '</h4>
                <hr>
                <p class="note-descriptor">' . $category->category_description . '</p>
            </div>
        </div>
    </a>
</li>';
}

暫無
暫無

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

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