【问题标题】:Display wordpress posts using get_posts - first post shows no date使用 get_posts 显示 wordpress 帖子 - 第一篇帖子不显示日期
【发布时间】:2012-05-02 14:50:53
【问题描述】:

您好,我正在使用 get_posts 获取所有标记为“新闻”的帖子并将它们显示在给定页面上。我正在使用 the_date() 来获取日期,但奇怪的是第一个帖子没有显示日期,而在此之后的所有帖子都显示日期正常。此外,我使用此相同的代码在另一个页面上显示标记为“博客”的帖子,但它们工作正常。

这是页面: http://appshare.nsdesign7.net/news/

这也是使用相同代码但工作正常的另一个页面: http://appshare.nsdesign7.net/blog/

<? $pageTitle = wp_title('',false,'');
if ($pageTitle == "  News") { ?>


 <?php $appsharenewspage = array( 'numberposts' => 10, 'order'=> 'ASC', 'orderby'=>     'title', 'category' => 3 ); 
 $postslist = get_posts( $appsharenewspage ); foreach ($postslist as $post) :     setup_postdata($post); ?> 
     <article class="newsstyle">
        <span class="imagestyle"><?php the_post_thumbnail(array(120,120)); ?>    </span>
        <h3><?php the_title(); ?></h3>
        <span class="date"><?php the_date(); ?></span>
       <?php the_excerpt(); ?>
           <div class="clear"></div>
    </article>
<?php endforeach; ?>

  <?php } ?>

【问题讨论】:

    标签: wordpress


    【解决方案1】:

    尝试使用:

    echo get_the_date();
    

    阅读特别说明http://codex.wordpress.org/Template_Tags/the_date

    【讨论】:

      【解决方案2】:

      the_date() 仅限于每天显示一次日期。因此,如果您在同一天有多个帖子,它只会显示在其中一个帖子上。

      改用 the_time。

      【讨论】:

        【解决方案3】:

        尝试改用&lt;?php echo get_the_date(); ?&gt;

        如果帖子仅在同一天发布,则 the_date 显示日期。

        参考:http://codex.wordpress.org/Function_Reference/get_the_date

        【讨论】:

          【解决方案4】:

          日期每天只出现一次。即对于同一天的 2 个帖子,一个将没有日期。这是一个WP功能。为了得到你想要的东西,用 php 函数获取时间。尝试使用the_time() 而不是the_date()

          【讨论】:

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