我有一个类别,叫做事件。它被分配到一个职位。因此,我创建了以下循环:
$args = array (\'category_name\' => \'events\', \'posts_per_page\' => 4, \'orderby\' => \'date\', \'order\' => \'DESC\' );
$category_posts = new WP_Query($args);
if ($category_posts->have_posts()) {
while ($category_posts->have_posts()) {
$category_posts->the_post();
var_dump($category_posts->the_post());
?>
<div class="col-md-6">
<?php $category_posts->the_post_thumbnail(array(\'class\' => \'events-image\')); ?>
</div>
<div class="col-md-6">
<h4><?php echo $category_posts->the_title(); ?></h4>
<span class="date"><?php echo date(\'M j, Y\', $category_posts->get_the_date()); ?></span>
<p><?php echo implode(\' \', array_slice(str_word_count($category_posts->the_content(), 2), 0,120)); ?> [...]</p>
</div>
<?php
}
}
请注意var_dump($category_posts->the_post());
它来到这里并这样做var_dump
但输出是NULL
. wtf?令人困惑的是,它有帖子,它进入while语句,但$category_posts->the_post()
是否为空?这几乎毫无意义。