我知道这很简单,但由于某种原因,我只是没有找到我,而Google今天没有帮助我。如何显示wordpress页面内容?
我想输出页面内容,我该怎么做?
我以为是这样的:
<?php echo the_content(); ?>
我知道这很简单,但由于某种原因,我只是没有找到我,而Google今天没有帮助我。如何显示wordpress页面内容?
我想输出页面内容,我该怎么做?
我以为是这样的:
<?php echo the_content(); ?>
@Marc乙感谢您的评论。帮助我发现这一点:
<?php if (have_posts()) : while (have_posts()) : the_post();
the_content();
endwhile; else: ?>
<p>Sorry, no posts matched your criteria.</p>
<?php endif; ?>
这是更简洁:
<?php echo get_post_field('post_content', $post->ID); ?>
,这甚至更多:
<?= get_post_field('post_content', $post->ID) ?>
谢谢,这比预期更难找到。 – socca1157 2016-08-26 01:50:56
只是把这个代码在你的内容的div
<?php
// TO SHOW THE PAGE CONTENTS
while (have_posts()) : the_post(); ?> <!--Because the_content() works only inside a WP Loop -->
<div class="entry-content-page">
<?php the_content(); ?> <!-- Page Content -->
</div><!-- .entry-content-page -->
<?php
endwhile; //resetting the page loop
wp_reset_query(); //resetting the page query
?>
页面内容,可以显示容易,完美这样:
<?php if(have_posts()) : ?>
<?php while(have_posts()) : the_post(); ?>
<h2><?php the_title(); ?></h2>
<?php the_content(); ?>
<?php comments_template('', true); ?>
<?php endwhile; ?>
<?php else : ?>
<h3><?php _e('404 Error: Not Found'); ?></h3>
<?php endif; ?>
注:
在显示内容方面 - I) comments_template()函数是一个可选的使用,如果您需要以启用对不同功能的评论。
ⅱ) _E()函数也是可选的,但不是仅仅示出了通过<p>
文本更有意义&有效。而首选的风格化的404.php可以创建重定向。
对于那些不喜欢看恐怖代码PHP标签炸开到处人...
<?php
if (have_posts()):
while (have_posts()) : the_post();
the_content();
endwhile;
else:
echo '<p>Sorry, no posts matched your criteria.</p>';
endif;
?>
@Sydney尝试把wp_reset_query()调用循环之前。 这将显示您的页面的内容。
<?php
wp_reset_query(); // necessary to reset query
while (have_posts()) : the_post();
the_content();
endwhile; // End of the loop.
?>
编辑:试试这个,如果你有一些你以前跑过的其他循环。 放置wp_reset_query();你在哪里找到最合适的,但是在你调用这个循环之前。
大多数WordPress功能只有在“The Loop”里面才能正常工作,http://codex.wordpress.org/The_Loop,特别是如果你想显示内容 – 2011-03-28 22:27:02
另外,你不需要“回声”。 the_content()隐式回声。 – windyjonas 2011-03-28 23:12:45