为什么我无法获得帖子的内容?

时间:2012-10-29 09:31:22

标签: wordpress

我的代码:

<div class="date"><?php the_time('d') ?> <?php the_time('M') ?></div>
<h2 class="titolo" style="min-height:0;"><?php the_title(); ?></h2>                                                                        
<div class="descrizione"><?php the_content(); ?></div>

时间和头衔是正确的。但内容是空的?

事实上,尝试:

$pr=get_posts();
print_r($pr);

我在数组中看到了标题和描述。我哪里错了?

2 个答案:

答案 0 :(得分:2)

试试这个

<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<div class="date"><?php the_time('d') ?> <?php the_time('M') ?></div>
<h2 class="titolo" style="min-height:0;"><?php the_title(); ?></h2>                                                                        
<div class="descrizione"><?php the_content(); ?></div>
<?php endwhile; else: ?>
<div class="alert alert-warning"><h4>Warning</h4><p><?php _e('Sorry, no posts matched your criteria.'); ?></p></div>
<?php endif; ?>

答案 1 :(得分:0)

你可以使用$ content = get_the_contnet();或$ content = $ post-&gt; post_content;

然后将$ content视为普通的php变量。

相关问题