the image is worth a thousand words. take a look at it.
你知道craigslist是如何按日期组织帖子的。。ex公司Tue 3
Wed 4
Thurs 5
我知道wordpress帖子默认按日期组织。看看这个有什么想法吗?顺便说一句,如果这没有意义让我知道。德克萨斯州
the image is worth a thousand words. take a look at it.
你知道craigslist是如何按日期组织帖子的。。ex公司Tue 3
Wed 4
Thurs 5
我知道wordpress帖子默认按日期组织。看看这个有什么想法吗?顺便说一句,如果这没有意义让我知道。德克萨斯州
你可能会注意到,我或多或少地为Matt的网站做了这样的事情:http://ma.tt. 每套帖子按天分组。基本原则是在循环中跟踪你的一天,然后只在日期发生变化时打印日期和相关内容。
进行基本循环:
if ( have_posts() ) : while ( have_posts() ) : the_post();
the_title();
the_content();
endwhile; endif;
这只是打印当前循环中所有内容的标题和内容(没有任何格式或任何内容)。现在,您希望它在每次日期更改时都弹出一个新日期。因此,您需要跟踪它何时发生变化。像这样:$loopday = \'\';
if ( have_posts() ) : while ( have_posts() ) : the_post();
if ($loopday !== get_the_time(\'D M j\')) {
$loopday = get_the_time(\'D M j\');
echo $loopday;
}
the_title();
the_content();
endwhile; endif;
这样做的目的是将要输出的日期存储到变量中。每次通过循环,它都会再次获取它并检查它是否已更改。如果它没有改变,那么什么也不会发生。如果已更改,则使用新的日期字符串设置变量,输出它,然后继续。显然,这只是一个例子。具体细节取决于现有循环的工作方式以及输出信息的方式。
虽然默认情况下,\\u date()确实可以做到这一点,但出于格式方面的原因,有时自己用这种方式更容易做到。
正如@goldenapples所指出的,如果您的模板使用了the\\u date();模板标记,默认情况下,它将自己完成这一切。我记得第一次使用WordPress时我很困惑,我不知道如何让它停止这样做。
你已经测试过了吗?这不是你得到的结果?这可能只是更改模板使用的标记的问题。
干杯
UPDATE根据评论中的注释进行更新。在这里,将此内容而不是循环
if (have_posts()) : while (have_posts()) : the_post();
if($day_check = \'\'){ $day_check = $post->date}
if ($day_check = $post->date){
if (!$day_echod){
echo \'<div class="date">\'.the_date().\'</div>\';
$day_echod = true;
}
}else{
$day_check = the_date();
echo \'<div class="date">\'.the_date().\'</div>\';
}
?>
<div class="title_link">
<a href="<?php the_permalink(); ?>"><?php the_title() ;?></a>
</div>
<?php
<?php endwhile; ?>
<?php endif; ?>
get\\u the\\u date()或get\\u the\\u time()调用会使结果过于复杂。只需使用\\u date(),默认情况下,每天只打印一次帖子的日期。
参见Codex关于此主题的文章:
我应该如何使用posts\\u where将meta\\u值从字符串更改为整数?