wordpress循环与其他元素

时间:2018-01-10 22:14:33

标签: php wordpress

我为特定类别创建了帖子模板,其中包括缩略图,标题,摘录,并且我使用自定义内容向模板添加了额外的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();                
      ?>

1 个答案:

答案 0 :(得分:0)

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

get_post_meta();

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