【问题标题】:get_the_date(); displays the date of wordpress installation, not postget_the_date();显示 wordpress 安装日期,而不是发布日期
【发布时间】:2015-02-06 09:44:38
【问题描述】:

我无法在 wordpress 中显示每个帖子的日期。对于每篇文章,它显示的是安装日期,而不是发布日期(每篇文章都在不同的日期发布,但现在都显示相同的日期,这似乎是随机的)。试着把 get_the_date();在没有运气的每个洛普。有谁知道为什么?

$postsnumber = $nm_theme_options['numberposts']; 
        $args = array( 'numberposts' => "$postsnumber" );
        $recent_posts = wp_get_recent_posts( $args );
        $date = get_the_date(); 
        foreach( $recent_posts as $recent ){                 
            echo '<li><a href="' . get_permalink($recent["ID"]) . '">' .  $date .' '. $recent["post_title"].'</a> </li> ';
    }

【问题讨论】:

  • 您不想获取每个帖子的日期吗,这意味着您需要在循环中调用它
  • 如前所述,将其放入循环中并没有什么不同,但是是的,我会保留它。
  • 那么请说明如何你把它放在那里 - 特别是,你是否使用帖子 ID 作为参数?

标签: php html wordpress date timestamp


【解决方案1】:

找到了解决我的问题的方法!

<?php
        $postsnumber = $nm_theme_options['numberposts']; 
        $args = array( 'numberposts' => "$postsnumber" );
        $recent_posts = wp_get_recent_posts( $args );

        foreach( $recent_posts as $recent ){    
            echo '<li><a href="' . get_permalink($recent["ID"]) . '">' .  date('d.m.y', strtotime($recent['post_date'])) .' '. $recent["post_title"].'</a> </li> ';
    }
    ?>

很抱歉在这方面是新手,但感谢您的帮助!

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-07-24
    • 1970-01-01
    • 2023-04-05
    相关资源
    最近更新 更多