【发布时间】:2013-02-19 11:32:36
【问题描述】:
我正在尝试确定是否可以在一个页面上存档多个帖子类型,我为每个帖子类型都有一个单独的存档,工作正常,但我还想要另一个可以存档它们的页面。我对 WP 还是很陌生,所以我完全不确定这是否可行,但到目前为止我所做的工作并不正常:
<?php query_posts('post_type=type01'); ?>
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<a href="<?php the_permalink(); ?>">
<div class="type01-div" data-value="<?php
$date = DateTime::createFromFormat('dnY', get_field('type01_date_select'));
echo $date->format('dnY');
?>">STUFF HERE</div>
</a>
<?php endwhile; endif; ?>
<?php query_posts('post_type=type02'); ?>
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<a href="<?php the_permalink(); ?>">
<div class="type02-div" data-value="<?php
$date = DateTime::createFromFormat('dnY', get_field('type02_date_select'));
echo $date->format('dnY');
?>">STUFF HERE</div>
</a>
<?php endwhile; endif; ?>
所以'type01' 的所有帖子都显示出来了,但'type02' 的帖子却没有。可以同时存档吗?但在单独的循环中,因为每种帖子类型都将包装在不同的 div 类中。
【问题讨论】:
-
我不确定.. 但是尝试在 endif 之后添加 wp_reset_query();在您的新 query_posts 之前。作为旁注,请查看此链接:codex.wordpress.org/Function_Reference/wp_reset_query 它建议您使用另一种方法来查询帖子。
-
仅供参考,有一个 WP 特定的 StackExchange 站点:wordpress.stackexchange.com - 尽管据我所知,这些问题在这里也很受欢迎(只要与编程相关)
标签: php html wordpress archive