【问题标题】:Wordpress LOOP [Only title and data]Wordpress LOOP [只有标题和数据]
【发布时间】:2013-09-06 15:59:27
【问题描述】:

我有一个 wordpress,我想用一个 php 循环来循环我的帖子,这样我就可以得到我所有的帖子,问题是我只想要帖子的标题、内容和日期.. .

<?php 
     while ( have_posts() ) : the_post(); 
         get_template_part( 'content', get_post_format() ); 
         echo "<br/><br/>";
     endwhile; 
?>

这是循环的通用代码,我尝试搜索 get_post_format() 函数,所以我只能得到我需要的东西,但没有人能帮忙吗?

【问题讨论】:

    标签: php wordpress loops


    【解决方案1】:

    在循环中使用the_title()the_date()the_content()

    the_title(); //displays post title
    the_content(); //displays post content
    the_date(); //displays post date
    

    【讨论】:

      【解决方案2】:

      在循环中简单调用the_title(),the_content(),the_date()

      <?php 
           while ( have_posts() ) : the_post(); 
               the_title();
               the_content();
               the_date();
               the_time('F jS, Y');
           endwhile; 
      ?>
      

      The_Loop_in_Action

      【讨论】:

        【解决方案3】:

        对于普通帖子get_post_format 返回布尔值FALSEget_template_part 基本上将它的字符串参数与“-”连接起来,并包含带有结果名称的模板。如果get_post_format()FALSE,那么它将包括content.php。我会用自定义字符串替换get_post_format(),并创建content-something.php 作为content.php 的副本,按照您需要的方式对其进行编辑。

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2018-11-23
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多