the_content()或has_post都没有在我的网站上显示内容(帖子)

问题描述 投票:0回答:1

这是我的页面的链接: http://list.thorsteinnhelgason.is/index.php/blog/

这是我的代码:

<div class="container">

    <div id="content">

         <?php 
        while ( have_posts() )
        {
            the_post();
    ?>
    <h2><?php the_title(); ?></h2>
    <?php the_content(); ?>
    <?php
        }
    ?>

        </div>

这是我的Single.php文件的循环,它没有在我的帖子网站上显示任何帖子内容。我是否需要在其他模板(functions.php例如)中调用该操作以获取我的帖子内容?或者它可能是什么原因导致它不起作用?希望你能帮我...

php wordpress file-get-contents
1个回答
0
投票

创建一个'if'语句来检查帖子是否存在(在'while'之前)。然后记得关闭/结束你的'while'和'if'循环。

<div class="container">
 <div id="content">

   <?php if (have_posts()) : while (have_posts()) : the_post(); ?>

      <h2><?php the_title(); ?></h2>
      <?php the_content(); ?>

    <?php 
      endwhile; 
      endif; 
     ?>

 </div>
</div>
© www.soinside.com 2019 - 2024. All rights reserved.