简体   繁体   English

排除Wordpress中的前两个类别

[英]Excluding first two categories in Wordpress

So I want to exclude the first two categories in the array, I want it to be dynamic so whether someone changes the orderby or parent, the exclude parameter will always exclude the first two in the array. 因此,我想排除数组中的前两个类别,我希望它是动态的,因此无论有人更改orderby还是父级,exclude参数将始终排除数组中的前两个类别。

I've searched long and far and can't seem to find any solution :(. 我已经搜索了很长时间,似乎找不到任何解决方法:(。

$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 );

On this line above, you are holding an array of categories. 在上面的这一行中,您持有一组类别。 [1][2][3][4][5][6][7][8][9] [1] [2] [3] [4] [5] [6] [7] [8] [9]

so if you unset it, it should work unset($categories[0]); 因此,如果您取消设置,它应该可以在unset($categories[0]);

edit you will also need array_value to fix the empty index 编辑您还将需要array_value来修复空索引

$newcat = array_values($categories);

before your foreach 在你的学习之前

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