我有一个archive-custom_post_name.php,用于输出自定义帖子类型的内容,如下所示:
<?php get_header(); ?>
<?php if ( have_posts() ) : ?>
<?php $post_type = $wp_query->get_queried_object(); ?>
// HTML Section header here
<?php get_template_part('loop', 'masonry'); ?>
<?php endif ?>
<?php get_footer(); ?>
这导致包含循环的模板部件文件:
<?php while ( have_posts() ) : the_post(); ?>
<?php get_template_part( 'content', 'masonry' ) ?>
<?php endwhile; ?>
这导致了一个模板部分,它为循环中的每个内容定义了HTML。
我需要的是修改文件archive-custom_post_name.php,以便它遍历自定义帖子类型的帖子使用的所有类别,为每个类别输出HTML部分标题,以及下面列出每个类别的所有帖子。 / p>
所以有三个类别,每个类别有三个帖子
// HTML Section header for cat one
// Post with cat one
// Post with cat one
// Post with cat one
// HTML Section header for cat two
// Post with cat two
// Post with cat two
// Post with cat two
// HTML Section header for cat three
// Post with cat three
// Post with cat three
// Post with cat three
正如我所提到的,我首选的方法是修改顶级文件archive-custom_post_name.php,而不是降低我可能的模板层次结构。
任何帮助表示感谢,我很难过!
答案 0 :(得分:0)
首先你需要得到所有的猫
http://codex.wordpress.org/Function_Reference/get_categories
每个(猫为猫)
在此循环中,您可以查询每个类别 http://codex.wordpress.org/Template_Tags/get_posts 然后只使用标题和内容标签正常显示内容