簡體   English   中英

如何在顯示wordpress的發布日期后添加文本?

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

當前,我有以下代碼在顯示日期時掛接。 我希望此代碼對列出的帖子(index.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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM