【问题标题】:Wordpress archive page with month following by posts + dateWordpress 存档页面,月份之后是帖子 + 日期
【发布时间】:2011-05-18 22:18:06
【问题描述】:

我正在尝试在具有特定布局的模板中添加存档部分。

我正在尝试获取如下列表:

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('&laquo; Older Entries') ?></div>
  <div class="alignright"><?php previous_posts_link('Newer Entries &raquo;') ?></div>
</div>
<?php else :
// Code here for no pages found
endif;
?>

我想知道我做错了什么或者它是否可能。谢谢!

【问题讨论】:

    标签: php wordpress archive


    【解决方案1】:

    IF循环只用于显示一次The Month,显示完月份后立即关闭:

    <?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('&laquo; Older Entries') ?></div>
      <div class="alignright"><?php previous_posts_link('Newer Entries &raquo;') ?></div>
    </div>
    <?php else :
    // Code here for no pages found
    endif;
    ?>
    

    【讨论】:

    • 我当时完全忘记回复了。这就像一个魅力,感谢您的努力!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-02-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-04-06
    • 2016-06-05
    • 1970-01-01
    相关资源
    最近更新 更多