我一直在进行长时间的谷歌搜索,试图找到解决方案......我正在创建一个使用 WordPress 安装来控制内容的 cv 管理器主题。我已设法按类别组织所有 WP 帖子,但也想在年份分组中列出这些帖子。目前我有这个:
<?php // Categories
$cvm_cat_args = array('orderby' => 'name', 'order' => 'ASC' );
$categories = get_categories($cvm_cat_args); ?>
<?php foreach($categories as $category) : ?>
<?php // Posts in category
$cvm_post_args = array( 'showposts' => -1, 'category__in' => array($category->term_id), 'caller_get_posts'=>1, 'order' => 'ASC' );
$posts = get_posts($cvm_post_args); ?>
<?php if ($posts) : ?>
<h1><?php echo $category->name ?></h1>
<?php foreach($posts as $post) : ?>
<?php setup_postdata($post); ?>
<h3><?php the_title(); ?></h3>
<small><?php the_time(); ?></small>
<?php the_excerpt() ?>
<?php endforeach; ?>
<?php endif; ?>
<?php endforeach; ?>
我坚持如何在类别中按年份顺序显示帖子,以便输出如下所示:
<h1>Category Name 1</h1>
<h2>2010</h1>
<h3>Post name 1</h3>
<p>Excerpt...</p>
<h3>Post name 2</h3>
<p>Excerpt...</p>
<h2>2009</h1>
<h3>Post name 3</h3>
<p>Excerpt...</p>
<h3>Post name 4</h3>
<p>Excerpt...</p>
<h1>Category Name 2</h2>
etc
任何帮助将不胜感激。
谢谢!