我正在尝试编写一个循环来按月显示帖子。到目前为止它已经相当顺利,我只需要帮助从数据库中提取post_content。我已成功使用wpdb获取了所有其余的帖子信息。 我像post_title一样尝试过post_content,但它不起作用。
这是我正在处理的示例页面。 http://asg.websolutionshack.com/events/
<div id="events" class="full">`
<?php
$months = $wpdb->get_results("SELECT DISTINCT MONTH(post_date) AS month , YEAR(post_date) AS year FROM $wpdb->posts WHERE post_status = 'publish' and post_date <> now() and post_type = 'event' GROUP BY month, year ORDER BY post_date DESC");
$posts = $wpdb->get_results("SELECT id, post_title, post_content, MONTH(post_date) AS month , YEAR(post_date) AS year , DAY(post_date) AS day FROM $wpdb->posts WHERE post_status = 'publish' and post_type = 'event' ORDER BY post_date DESC");
foreach($months as $this_month){ ?>
<div class="month_block">
<h2 class="month"><?php echo date("F", mktime(0, 0, 0, $this_month->month, 1, $this_month->year)); ?> <?php //echo $this_month->year; ?></h2>
<?php for ($i = 0; $i <= count($posts); $i++){?>`
<div class="entry">
<?php if(($this_month->year == $posts[$i]->year)&&($this_month->month == $posts[$i]->month)){?>
<span><?php echo $posts[$i]->month ?>.<?php echo $posts[$i]->day ?>.<?php echo $posts[$i]->year ?></span><h3><?php echo $posts[$i]->post_title; ?></h3>
<p><<?php echo $posts[$i]->post_content; ?><a href="<?php echo get_permalink($posts[$i]->id); ?>">Details ></a></p>
<?php } ?>
</div><!-- entry -->
<?php } ?>
</div><!-- month -->
`
感谢您提供给我的任何见解。