我想在wordpress主题的档案导航中复制以下标记。
HTML:
<ul>
<li>2012
<ul>
<li>December
<ul>
<li>Page 1</li>
<li>Page 2</li>
<li>Page 3</li>
</ul>
</li>
<li>November
<ul>
<li>Page 1</li>
<li>Page 2</li>
<li>Page 3</li>
</ul>
</li>
</ul>
</li>
</ul>
到目前为止,我有另外一篇文章,如何更新此代码输出像我的html年/月/帖子标题?
<?php
// Declare some helper vars
$previous_year = $year = 0;
$previous_month = $month = 0;
$ul_open = false;
// Get the posts
$myposts = get_posts('numberposts=-1&orderby=post_date&order=DESC&cat=13');
?>
<?php foreach($myposts as $post) : ?>
<?php
// Setup the post variables
setup_postdata($post);
$year = mysql2date('Y', $post->post_date);
$month = mysql2date('n', $post->post_date);
?>
<?php if($year != $previous_year || $month != $previous_month) : ?>
<?php if($ul_open == true) : ?>
</ul>
<?php endif; ?>
<h3><?php the_time('F Y'); ?></h3>
<ul class="month_archive">
<?php $ul_open = true; ?>
<?php endif; ?>
<?php $previous_year = $year; $previous_month = $month; ?>
<li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li>
<?php endforeach; ?>
</ul>
答案 0 :(得分:0)
您是否尝试过内置的wp_get_archives()
?
<?php wp_get_archives( array( 'type' => 'monthly' ) ); ?>
请参阅Codex for more info on this method。
<强>更新强>
尝试本WP论坛帖子末尾建议的其中一个插件:http://wordpress.org/support/topic/list-posts-by-year-and-month-archive-like
他们现在已经很老了,我不确定他们是否仍在工作。