【问题标题】:Neither the_content() or have_post is showing content (posts) on my sitethe_content() 或 have_post 都没有在我的网站上显示内容(帖子)
【发布时间】:2018-02-28 19:21:21
【问题描述】:

这是我页面的链接:
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)中调用该操作才能获取我的帖子的内容?或者它不起作用的原因是什么?希望你能帮助我...

【问题讨论】:

  • the_title 应该在循环内get_template_part 正在尝试加载另一个模板文件,因此在不知道 那个 文件内部的情况下,无法分辨。为了好玩,你为什么不添加the_title(); the_content(); 只是之前 get_template_part('content'); 看看会发生什么。
  • 你能用你的整个文件更新这个问题吗?正如 cal_b 所说,它必须在循环中。据我们所知,您在容器 div 上方调用它,或者您根本没有使用它
  • 我稍微简化了代码,但还是不行; &lt;div id="content"&gt; &lt;?php while ( have_posts() ) { the_post(); ?&gt; &lt;h2&gt;&lt;?php the_title(); ?&gt;&lt;/h2&gt; &lt;?php the_content(); ?&gt; &lt;?php } ?&gt; &lt;/div&gt;

标签: php wordpress file-get-contents


【解决方案1】:

创建一个“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>

【讨论】:

  • 谢谢@ianbeans 不幸的是,这也不起作用。 og认为是否有其他一些设置会影响帖子不显示?
  • 可能有一百件事会阻止内容呈现 - 我只是在修复您的代码。我建议按照这些教程学习 WordPress。 youtube.com/watch?v=oTRZYnYQlmo&t=1054s
  • 谢谢 - 我会看的。这是该页面的链接:list.thorsteinnhelgason.is/index.php/blog - 只要您可以立即看到是否有阻塞。
猜你喜欢
  • 1970-01-01
  • 2023-02-11
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-12-29
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多