是否按父类别页面显示10个子类别?

时间:2014-08-04 作者:Sathiya Moorthi

我使用以下代码在父类别页面中显示子类别。它在一个页面中显示所有子类别。我想每页显示10个子类别。请帮助我限制类别页面中的子类别。

我的代码:

<?php 

$cat = get_query_var(\'cat\');
$categories= get_categories(\'hide_empty=0&parent=\'.$cat);

if(!empty($categories)){

echo \'<div class="post-listing"><section id="list"><ul>\';

foreach ($categories as $categories_item) {

$mycat .= $category->cat_name;
echo $mycat;


        echo \'<li>\';
        echo \'<h2 class="post-box-title"><a href="\' . get_category_link( $categories_item->term_id ) . \'" title="\' . sprintf( __( "%s" ), $categories_item->name ) . \'" \' . \'>\' . $categories_item->name.\'</a> </h2> \';
        $terms = apply_filters( \'taxonomy-images-get-terms\', \'\' );
        if ( ! empty( $terms ) ) {
          foreach( (array) $terms as $term ) {
                if($term->term_id == $categories_item->term_id) {
                   print \'<div class="post-thumbnail"><a class="thumb" href="\' . esc_url( get_term_link( $term, $term->taxonomy ) ) . \'">\' . wp_get_attachment_image( $term->image_id, \'medium\' );
                   echo \'</div></a>\';
                 }
            }
            echo \'<p>\'. $categories_item->description; echo \'</p></li>\';
        }
    }

    echo \'</ul></section></div>\';
}else {
?>

1 个回复
SO网友:Bindiya Patoliya

请尝试以下方法:

get_categories(\'hide_empty=0&number=10&parent=\'.$cat);
有关更多参考信息,请访问link

此处数字表示:

number

(string)要返回的类别数

结束

相关推荐

从WP_LIST_CATEGORIES中删除‘Category’一词

我有以下代码:wp_list_categories();它输出我的所有类别,但是,它使它们成为列表元素的子元素,称为CATEGORIES.所以,我得到了一个无序的列表,如下所示:CATEGORIES * FASHION * DAILY FASHION CANDY * TRENDS * BEAUTY * ACCESSORIES * CELEBRITIES * LIFESTYLE 但是,我只需要:* FASHION * DAILY FA