我在侧栏中显示我的档案列表我已显示年份和月份但无法在谷歌上找到任何帮助以显示与他们之下的每个月相关的博客帖子
2016
October
Blog Topic 1
Blog Topic 2
September
Blog topic 1
Blog Topic 2
我显示年份和月份的代码是根据哪个工作正常但它没有显示每个特定月份的博客帖子标题:
<ul class="archive-list">
<?php global $wpdb, $month, $sposts;
$years = $wpdb->get_col("SELECT DATE_FORMAT(post_date_gmt, '%Y')
FROM $wpdb->posts
WHERE post_type = 'post' AND post_status = 'publish'
GROUP BY DATE_FORMAT(post_date_gmt, '%Y')
ORDER BY post_date_gmt DESC");
if ( $years && count($years) > 0 ) {
foreach ( $years as $y ) { ?>
<li><?php echo $y; ?></li>
<li>
<?php
$months = $wpdb->get_col("SELECT DATE_FORMAT(post_date_gmt, '%m')
FROM $wpdb->posts
WHERE post_type = 'post' AND post_status = 'publish'
AND DATE_FORMAT(post_date_gmt, '%Y') = $y
GROUP BY DATE_FORMAT(post_date_gmt, '%Y-%m')
ORDER BY post_date_gmt DESC");
if ($months) { ?>
<ul><?php
foreach($months as $m) {
echo '<li><a href="'.get_month_link($y, $m).'">'.$month[zeroise($m, 2)]."</a></li>";
} ?>
<!-- START:post title-->
<?php
$sql = "SELECT post_title FROM wp_posts WHERE
post_type = 'post' AND post_status = 'publish'
AND DATE_FORMAT(post_date_gmt, '%Y') = $y
AND DATE_FORMAT(post_date_gmt, '%m') = $m
GROUP BY DATE_FORMAT(post_date_gmt, '%Y-%m')
ORDER BY post_date_gmt DESC";
$results = $wpdb->get_results($sql) or die(mysql_error());
foreach( $results as $result )
{ echo $result->post_title; }
?>
<!--END:post title-->
</ul><?php
} ?>
<?php
}?>
</ul>