Wordpress:打印子类别帖子包括分类内页面模板下的(标题,永久链接和摘录)

时间:2013-03-20 16:09:26

标签: php wordpress categories

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

我只想问这是否可能?

==>目录页面(在6月号类别下)

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

=>子类别标题

 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是否有这种方法在特定的帖子类别下提取子类别..如何正确地在模板中显示它,就像我将为下一个问题创建另一个表内容它将自动打印所有子类别信息。请帮帮我。

由于

1 个答案:

答案 0 :(得分: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;

             }

             }
    ?>