相关疑难解决方法(0)

从特定父级获取Wordpress子类别

我正在构建一个小缩略图库,其中包含ID为406的类别的帖子.

有些帖子属于多个类别,我不知道如何获取属于406的子类别的类别名称.$post_cat[0]->name;返回一个类别,但我只需要它返回406的子级.

$thumbnails = get_posts('posts_per_page=10&cat=406');

foreach ($thumbnails as $thumbnail) {

   $args = array(
     'type' => 'post',
     'child_of' => 0,
     'parent' => 406,
   );
   $categories = get_categories ( $args );

   foreach ( $categories as $category) {
      $cat_name = $category->name;
      $cat_slug = $category->slug;
   }

    echo $cat_name;
    echo $cat_slug;

 }
Run Code Online (Sandbox Code Playgroud)

*编辑**

$thumbnails = get_posts('posts_per_page=10&cat=406');
foreach ($thumbnails as $thumbnail) {

  $post_cat = get_the_category( $thumbnail->ID );
  echo '<li><a class="side-thumb" href="' . get_permalink( $thumbnail->ID ) . '" title="' . esc_attr( $thumbnail->post_title …
Run Code Online (Sandbox Code Playgroud)

wordpress

3
推荐指数
1
解决办法
3万
查看次数

标签 统计

wordpress ×1