【问题标题】:wordpress loop with additional elements带有附加元素的wordpress循环
【发布时间】:2018-01-10 22:14:33
【问题描述】:

我为特定类别创建了帖子模板,其中包含缩略图、标题、摘录,我在模板中添加了带有自定义内容的附加 div,这些内容将自动生成,设为 div class= "custom"。我还在博客页面上创建了一个循环,显示该特定类别的所有帖子。我知道如何显示缩略图、标题、摘录,但不知道如何显示 .custom。我应该如何创建这个循环?谢谢

<?php
        if ( have_posts() ) :
          query_posts('cat=1');   
          while (have_posts()) : the_post();  
        ?>
        <div class = "programs-flex-item">
          <div class = "programs-flex-item__title"><?php the_title(); ?></div>
          <div class = "programs-flex-item__image"><?php the_post_thumbnail(); ?></div>
          <div class = "programs-flex-item__excerpt"><?php the_excerpt(); ?></div>
          <div class = "custom">HERE IS CUSTOM CONTENT!!!</div>

        </div>
         <?php 
          endwhile; 
          endif;
        wp_reset_query();                
      ?>

【问题讨论】:

  • 这里的CUSTOM CONTENT 是什么意思?你想在那里添加CUSTOM CONTENT 吗?
  • @AlivetoDie 它将是在帖子模板上使用 js 生成的随机 html 内容(例如,single.php)

标签: php wordpress


【解决方案1】:

存储自定义帖子值的最佳方式是元数据或帖子元数据。这是一个基本的键值对,可以通过使用自定义帖子字段插件进行扩展(选择任何你喜欢的)。在代码中你可以使用

get_post_meta();

获取帖子的元数据。链接here。另请查看answer 了解更多信息

【讨论】:

  • 好的,但是如果我不想拥有编辑此字段的权限,我只想在我的帖子模板上有一个可以循环使用的变量
猜你喜欢
  • 2019-07-16
  • 2017-02-16
  • 1970-01-01
  • 2019-07-12
  • 1970-01-01
  • 2016-02-21
  • 2022-10-05
  • 2013-12-17
  • 1970-01-01
相关资源
最近更新 更多