我是PHP和Wordpress的新手,我試圖完成的是按月份+年列出所有帖子。月份+年份顯示爲鏈接,點擊該鏈接即可切換日期。我的CSS代碼看起來像這樣,並正常工作(由jQuery完成切換功能)。使用php生成WP循環中的關閉div
<div class="monat"> <!-- month div -->
<a href="#" title="Oktober 2014" class="zeigeTage">Oktober 2014</a> <!-- Toggle Button -->
<div class="tage"> <!-- toggle div - shown when toggle button clicked -->
<a href="#" title="#" class="tag">12</a> <!-- day of month -->
<a href="#" title="#" class="tag">20</a> <!-- day of month -->
<a href="#" title="#" class="tag">22</a> <!-- day of month -->
<a href="#" title="#" class="tag">23</a> <!-- day of month -->
</div> <!-- end toggle div -->
</div> <!-- end month div -->
這就是我迄今爲止在php中完成的工作。問題是,我需要2日收盤的div末(類monat和類踏歌),我不知道如何實現它們在PHP代碼...
<?php
$prev_month = '';
$prev_year = '';
while(have_posts())
{
the_post();
if(get_the_time('F') != $prev_month || get_the_time('Y') != $prev_year)
{
echo '<div class="monat"><a href="#" title="#" class="zeigeTage">'.get_the_time('F Y').'</a><div class="tage">';
}
?>
<a href="<?php the_permalink(); ?>" title="#" class="tag"><?php the_time('j'); ?></a>
<?php
$prev_month = get_the_time('F');
$prev_year = get_the_time('Y');
}
?>
感謝您的幫助, 安德烈亞斯