Wordpress:single.php 不显示 the_content()
[英] Wordpress: single.php doesn't display the_content()
本文介绍了Wordpress:single.php 不显示 the_content()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在创建一个自定义的 Wordpress 主题,但我似乎无法让 single.php 模板工作.下面是我写的代码.标题出现了,但内容没有.任何想法为什么不是?
<div id="content" role="main"><div <?php post_class() ?>id="post-<?php the_ID(); ?>"><h2><a href="<?php the_permalink() ?>"rel="bookmark" title="永久链接到<?php the_title_attribute(); ?>"><?php the_title();?></a></h2><small><?php the_time('F jS, Y') ?><!-- 来自 <?php the_author() ?>--></小><div class="entry"><?php the_content();?>
<p class="postmetadata"><?php the_tags('标签:', ', ', '<br/>');?>发表于 <?php the_category(', ') ?>|<?php edit_post_link('编辑', '', ' | ');?><?php comments_popup_link('没有评论»', '1 条评论»', '% 评论»');?></p>
</div><!-- #content -->
查看这里的输出截图:
解决方案
the_content()
未显示,因为它必须位于 The Loop - 看看这里的文档»
您需要将代码更改为:
if ( have_posts() ) : while ( have_posts() ) : the_post();内容();终了;别的:<p><?php _e('抱歉,没有符合您条件的帖子.');?></p>万一;
如果您始终确定有要显示的内容,则可以省略 else
:) 或者只需查看原始的 single.php
,您可以在其中找到 循环总是围绕着the_content()
这是您可能想要使用/开始的整个 single.php:
<div id="content" role="main"><?php if ( have_posts() ) : while ( have_posts() ) : the_post();?><div <?php post_class() ?>id="post-<?php the_ID(); ?>"><h2><a href="<?php the_permalink() ?>"rel="bookmark" title="永久链接到<?php the_title_attribute(); ?>"><?php the_title();?></a></h2><small><?php the_time('F jS, Y') ?><!-- 来自 <?php the_author() ?>--></小><div class="entry"><?php the_content();?>
<p class="postmetadata"><?php the_tags('标签:', ', ', '<br/>');?>发表于 <?php the_category(', ') ?>|<?php edit_post_link('编辑', '', ' | ');?><?php comments_popup_link('没有评论»', '1 条评论»', '% 评论»');?></p>
<?php endwhile;万一;?></div><!-- #content -->
I'm creating a custom Wordpress Theme and I can't seem to get the single.php template to work. Below is the code I have written. The title comes up but the content doesn't. Any Ideas why it isn't?
<?php
/**
* The Template for displaying all single posts.
*/
get_header(); ?>
<div id="content" role="main">
<div <?php post_class() ?> id="post-<?php the_ID(); ?>">
<h2><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></h2>
<small><?php the_time('F jS, Y') ?> <!-- by <?php the_author() ?> --></small>
<div class="entry">
<?php the_content(); ?>
</div>
<p class="postmetadata"><?php the_tags('Tags: ', ', ', '<br />'); ?> Posted in <?php the_category(', ') ?> | <?php edit_post_link('Edit', '', ' | '); ?> <?php comments_popup_link('No Comments »', '1 Comment »', '% Comments »'); ?></p>
</div>
</div><!-- #content -->
See here for a screenshot of the output:
解决方案
the_content()
is not displaying because it has to be inside the The Loop - take a look at the docs here »
You need to change your code to this:
if ( have_posts() ) : while ( have_posts() ) : the_post();
the_content();
endwhile;
else:
<p><?php _e('Sorry, no posts matched your criteria.'); ?></p>
endif;
You can leave out the else
if you are always sure you have content to display :) Or just take look at the original single.php
where you can find The Loop always surrounds the_content()
edit:
Here is the whole single.php you might wanna use/start with:
<?php
/**
* The Template for displaying all single posts.
*/
get_header(); ?>
<div id="content" role="main">
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<div <?php post_class() ?> id="post-<?php the_ID(); ?>">
<h2><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></h2>
<small><?php the_time('F jS, Y') ?> <!-- by <?php the_author() ?> --></small>
<div class="entry">
<?php the_content(); ?>
</div>
<p class="postmetadata"><?php the_tags('Tags: ', ', ', '<br />'); ?> Posted in <?php the_category(', ') ?> | <?php edit_post_link('Edit', '', ' | '); ?> <?php comments_popup_link('No Comments »', '1 Comment »', '% Comments »'); ?></p>
</div>
<?php endwhile; endif; ?>
</div><!-- #content -->
这篇关于Wordpress:single.php 不显示 the_content()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!