我已经创建了自定义帖子类型(Match)和自定义分类法(Team),并使团队分类法可用于普通帖子(该团队的新闻)和匹配自定义帖子类型。
然而,在归档模板页面上,我创建了分类团队。php中,帖子并没有分为新闻部分和匹配部分。
我尝试过各种解决方案,但目前两者都显示相同的内容-所有帖子和球队的所有比赛。
我恢复了第二部分“匹配”,以展示我在这里和各种教程网站上阅读答案时尝试的两种方法。
<?php
/**
* The template for displaying Archive pages.
*
* Learn more: http://codex.wordpress.org/Template_Hierarchy
*
* @package aThemes
*/
get_header(); ?>
<section id="primary" class="content-area">
<div id="content" class="site-content" role="main">
<?php
// This sets out a variable called $term - we\'ll use it ALOT for what we\'re about to do.
$term = get_term_by( \'slug\', get_query_var( \'term\' ), get_query_var( \'taxonomy\' ) ); ?>
<!-- See how we used the variable to let Wordpress know we want to display the title of the taxonomy? -->
<div id="matchheader"><?php echo $term->name; ?></div>
<!-- Using the same variable, we can use it to display the posts that the artist has been tagged in -->
<h2><?php echo $term->name; ?> News</h2>
<ul class="newslist">
<?php $args = array(
\'post_type\' => \'match\',
\'child_of\' => 0,
\'parent\' => \'\',
\'orderby\' => \'name\',
\'order\' => \'ASC\',
\'hide_empty\' => 1,
\'hierarchical\' => 1,
\'exclude\' => \'\',
\'include\' => \'\',
\'number\' => \'\',
\'taxonomy\' => \'team\',
\'pad_counts\' => false
);
$categories = get_categories( $args );
foreach ( $categories as $cat ) {
$posts_array = get_posts(
array(
\'posts_per_page\' => -1,
\'post_type\' => \'match\',
\'tax_query\' => array(
array(
\'taxonomy\' => \'team\',
\'field\' => \'term_id\',
\'terms\' => $cat->term_id,
)
)
)
); }
?>
<?php while (have_posts()) : the_post(); ?>
<li><a href="<?php the_permalink() ?>" rel="bookmark"><?php the_title(); ?></a> - <?php the_time(\'d M Y\'); ?></li>
<?php endwhile; ?>
<?php wp_reset_query(); ?>
</ul>
<h2><?php echo $term->name; ?> Matches</h2>
<ul class="matchlist">
<?php while (have_posts()) : the_post(); ?>
<li><a href="<?php the_permalink() ?>" rel="bookmark"><?php the_title(); ?></a> - <?php the_time(\'d M Y\'); ?></li>
<?php endwhile; ?>
</ul>
</div><!-- #content -->
</section><!-- #primary -->
<?php get_sidebar(); ?>
<?php get_footer(); ?>
我如何分离存档页面,以便它们分别显示每个团队的新闻和比赛?