如何在显示WordPress的发布日期后添加文本


How do you add text after displaying the post date for wordpress?

目前,我有以下代码,可以在显示日期时挂钩。我希望它编码以影响列出的帖子(索引.php)和单个帖子的日期。

function rating_after_date()
{
return printf(
     'Ratings: %s'
    ,get_post_meta( get_the_ID(), 'post_rating', true )
);
}
add_action( 'get_the_date', 'rating_after_date' );

它更改了日期,但不会更改我想要的方式:

Ratings: 0Ratings: 010

我希望帖子显示日期如下:

March 22, 2016 | Rating: <somenumber>

感谢您的任何帮助。

该过滤器接受参数日期,日期格式和帖子ID。你可以做这样的事情:

function rating_after_date($date, $d, $post_id)
{
    return $date . printf(' | Ratings: %s'
                 ,get_post_meta( get_the_ID(), 'post_rating', true )
);
add_action( 'get_the_date', 'rating_after_date' );

请注意,您应该调整新筛选器的优先级,以便它在堆栈末尾执行。

这里有一个很好的例子: https://codex.wordpress.org/Plugin_API/Filter_Reference/get_the_date