我正在尝试在具有特定布局的模板中设置存档部分。
我想获得如下列表:
FEBRUARI
01-02-2011 - Title 3
03-02-2011 - Title 4
JANUARY
01-01-2011 - Title
03-01-2011 - Title 2
< older entries newer entries>`
我正在尝试让我的代码工作,但它失败了,每月只显示一个帖子。
<?php
// List Pages by Month/Day
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$args = array(
'paged' => $paged,
'post_type' => 'post',
'posts_per_page' => 10,
);
query_posts($args);
if (have_posts()) : while (have_posts()) : the_post();
$this_dt = get_the_time('M',$post->post_date);
if ($curr_dt != $this_dt) { ?>
<h4><?php echo $this_dt; ?></h4>
<ul class="artikelen">
<li><a href="<?php the_permalink(); ?>"><span><?php echo get_the_time('d');?> - <?php echo get_the_time('M');?> | <?php echo get_the_time('Y'); ?> |</span><?php the_title();?></a></li><?php echo "</ul>"; }
$curr_dt = $this_dt; endwhile; ?>
<div class="navigation">
<div class="alignleft"><?php next_posts_link('« Older Entries') ?></div>
<div class="alignright"><?php previous_posts_link('Newer Entries »') ?></div>
</div>
<?php else :
// Code here for no pages found
endif;
?>
我想知道我做错了什么或者是否可能。谢谢!
答案 0 :(得分:1)
IF循环仅用于显示月份一次,在显示月份后右键显示:
<?php
// List Pages by Month/Day
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$args = array(
'paged' => $paged,
'post_type' => 'post',
'posts_per_page' => 10,
);
query_posts($args);
if (have_posts()) : while (have_posts()) : the_post();
$this_dt = get_the_time('M',$post->post_date);
if ($curr_dt != $this_dt) { ?>
<h4><?php echo $this_dt; ?></h4>
<?php } ?>
<ul class="artikelen">
<li><a href="<?php the_permalink(); ?>"><span><?php echo get_the_time('d');?> - <?php echo get_the_time('M');?> | <?php echo get_the_time('Y'); ?> |</span><?php the_title();?></a></li><?php echo "</ul>";
$curr_dt = $this_dt; endwhile; ?>
<div class="navigation">
<div class="alignleft"><?php next_posts_link('« Older Entries') ?></div>
<div class="alignright"><?php previous_posts_link('Newer Entries »') ?></div>
</div>
<?php else :
// Code here for no pages found
endif;
?>