WordPress只获得类别的孙子

时间:2017-10-06 09:57:34

标签: php wordpress wordpress-theming themes custom-wordpress-pages

我有以下类别结构:

Category:
 - child:
  - grandchild

我怎样才能得到孙子孙女?下面我有我用来获取子类别的代码。

$obj_id = get_queried_object_id(); // category ID
    $categories = get_categories( array(
        'child_of' => $obj_id,
        'orderby' => 'name',
        'order'   => 'ASC'
    ) );

foreach( $categories as $category ) {
    $category_link = sprintf( 
      '<a href="%1$s" alt="%2$s"><h4>%3$s</h4></a>',
        esc_url( get_category_link( $category->term_id ) ),
        esc_attr( sprintf( __( 'View all posts in %s', 'textdomain' ), $category->name ) ),
        esc_html( $category->name )
    );

    echo '<div class="col-sm-3"> <div class="cat"> ';

    echo '<div class="img-scale"><a class="img-cat-cont" href="';
    echo get_category_link( $category->term_id );
    echo '">';

    echo'</a></div>';

    echo sprintf( esc_html__( '%s', 'textdomain' ), $category_link );

    echo '</div></div>';

} 

0 个答案:

没有答案