我试图在wordpress主题中为我的新闻栏目创建一个嵌套的帖子档案:
<div class="blog-list-archive">
<?php
/**/
$years = $wpdb->get_col("SELECT DISTINCT YEAR(post_date)
FROM $wpdb->posts WHERE post_status = 'publish'
AND post_type = 'post' ORDER BY post_date DESC");
foreach($years as $year) :
?>
<li><a href="JavaScript:void()"><?php echo $year; ?></a>
<ul class="archive-sub-menu">
<? $months = $wpdb->get_col("SELECT DISTINCT MONTH(post_date)
FROM $wpdb->posts WHERE post_status = 'publish' AND post_type = 'post'
AND YEAR(post_date) = '".$year."' ORDER BY post_date DESC");
foreach($months as $month) :
?>
<li><a href="<?php echo get_month_link($year, $month); ?>">
<?php echo date( 'F', mktime(0, 0, 0, $month) );?></a>
</li>
<?php endforeach;?>
</ul>
</li>
<?php endforeach; ?>
</div>
如何扩展此功能以显示每个月的帖子?另外,我只是想在“新闻”下获取帖子。类别是&#39; 13&#39;。
只是为了说明我需要这种格式:
2013
2012
答案 0 :(得分:2)
将此代码放在打印月份名称的代码下面。
global $wpdb;
$sposts = $wpdb->get_col( "
SELECT ID
FROM $wpdb->posts
WHERE MONTH(post_date) = '$month'
AND YEAR(post_date) = '$year'
AND post_status = 'publish'
AND 'post_type' = 'post'
ORDER BY post_date DESC" );
foreach( $sposts as $spost ) {
echo '<a href="' . get_permalink( $spost ) . "'>" . get_the_title( $spost ) . "</a>";
}