Tho*_*ole 21 php wordpress wordpress-theming
我正在创建一个自定义的Wordpress主题,我似乎无法使single.php模板工作.以下是我编写的代码.标题出现但内容没有.任何想法为什么不是?
<?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 -->
Run Code Online (Sandbox Code Playgroud)
请参阅此处获取输出的屏幕截图:
lor*_*key 61
the_content()
没有显示,因为它必须在The Loop中 - 看看这里的文档»
您需要将代码更改为:
if ( have_posts() ) : while ( have_posts() ) : the_post();
the_content();
endwhile;
else:
<p><?php _e('Sorry, no posts matched your criteria.'); ?></p>
endif;
Run Code Online (Sandbox Code Playgroud)
else
如果你总是确定你有内容要显示,你可以省略:)或者只是看看原来single.php
你可以找到的地方The Loop always aroundsthe_content()
编辑:
这是你可能想要使用/开始的整个single.php:
<?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 -->
Run Code Online (Sandbox Code Playgroud)