0

嗨基本上我有一个页面模板。就像目录一样。我不想要插件,因为我仍然想控制代码。

我只想问这可能吗?

==> 目录页面(在类别六月刊下)

然后打印特定类别下的所有子类别信息。像这种格式:

=> 子类别标题

 then Posts Under (this) Subcategory
 -> Post Title including Permalink
 -> Post Excerpt

 -> Post Title including Permalink
 -> Post Excerpt

 -> Post Title including Permalink
 -> Post Excerpt

=> 子类别 2 标题

 then Posts Under (this) Subcategory
 -> Post Title including Permalink
 -> Post Excerpt

 -> Post Title including Permalink
 -> Post Excerpt

 -> Post Title including Permalink
 -> Post Excerpt

=> 子类别 3 标题

 then Posts Under (this) Subcategory
 -> Post Title including Permalink
 -> Post Excerpt

 -> Post Title including Permalink
 -> Post Excerpt

 -> Post Title including Permalink
 -> Post Excerpt

等等..

我只是想知道 wordpress 是否有这种在特定帖子类别下提取子类别的方法。如何在模板中正确显示它,就像我要为下一个问题创建另一个表格内容一样它将自动打印所有子类别信息。请帮我。

谢谢

4

1 回答 1

0

试试这个...未经测试

<?php 

        $args = array(
            'type'                     => 'post',
            'child_of'                 => 0,
            'parent'                   => '1', //Only get child categories
            'orderby'                  => 'name',
            'order'                    => 'ASC',
            'hide_empty'               => 1,
            'taxonomy'                 => 'category',
            'pad_counts'               => false 
        );

        $categoryList = get_categories($args);

            if(!empty($categoryList)){

            foreach($categoryList as $category){

                          $postArgs = array(
                    'cat' => $category->id,
                            'post_type' => 'post'   //Use other options as needed
                         );                    

                query_posts($postArgs);

                        while ( have_posts() ) : the_post();
                echo get_the_title();
                echo get_permalink();
                        echo get_the_excerpt();
                endwhile;

             }

             }
    ?>
于 2013-03-20T16:34:10.567 回答