【问题标题】:making first wordpress theme, the loop and template functions not working properly制作第一个 wordpress 主题,循环和模板功能无法正常工作
【发布时间】:2016-07-03 23:23:12
【问题描述】:

我正在关注this 教程,但到目前为止我所做的并不能正常工作。我已经到了开始使用循环的地步——这是我的代码:

index.php

<?php get_header(); ?>
  <div class="row">
    <div class="col-sm-8 blog-main">
      <?php 
      if ( have_posts() ) : while ( have_posts() ) : the_post();

        get_template_part( 'content', get_post_format() );

      endwhile; endif; 
      ?>
    </div><!-- /.blog-main -->
    <?php get_sidebar(); ?>
  </div><!-- /.row -->
  <?php get_footer(); ?>
</div><!-- /.container -->`

content.php

<div class="blog-post">
    <h2 class="blog-post-title"><?php the_title(); ?></h2>
    <p class="blog-post-meta"><?php the_date(); ?><a href="#"><?php the_author(); ?></a></p>

    <?php the_content(); ?>
</div><!-- /.blog-post -->

我有两个帖子,但只有最新的帖子被显示(通过循环)并且在显示的帖子中 - 唯一显示的部分是标题。因此,the_date()the_author()the_content() 函数似乎由于某种原因无法正常工作,并且循环仅获取其中一篇文章(最新一篇)。

怎么了?谢谢。

【问题讨论】:

  • 对于帖子显示,请在 WP admin 中更改选项,对于数据和内容查看您的 css 样式。

标签: php html wordpress function loops


【解决方案1】:

我不确定我做了什么,但我去了 WP 管理员并单击主题的“自定义”,它在主题编辑器中正确加载 - 然后我去了该网站,它正在工作。我想也许我没有保存文件,而且我没有意识到 - 当我试图弄清楚时,我最终保存了文件,它开始工作了。

【讨论】:

    猜你喜欢
    • 2015-11-24
    • 2012-01-02
    • 1970-01-01
    • 2022-12-21
    • 1970-01-01
    • 1970-01-01
    • 2017-09-23
    • 2019-01-01
    相关资源
    最近更新 更多