[英]How do I format a post's date using shortcodes in Wordpress?
有人可以幫忙嗎? 我正在使用此短代碼在標題[mm-insert-date]下方顯示帖子的日期,它可以正常工作,但顯示為“ 2014-02-01 01:24:27”,我希望它讀取類似“ 2014年2月2日”,然后失去時鍾時間。 我已經從搜索等中嘗試了很多東西,但沒有任何幫助。
任何幫助,不勝感激!
這是主題function.php文件中的函數
function mm_insert_date_func($atts) {
// Insert the post date, with optional before and after strings.
// [mm-insert-date before='<h3>' after='</h3>']
global $post;
extract(shortcode_atts(array('before' => '', 'after' => '' ), $atts));
$output = "{$before}{$post->post_date}{$after}";
return $output;
}
add_shortcode('mm-insert-date', 'mm_insert_date_func');
我有一個可行的解決方案:
$output = $before . date('M j Y', strtotime($post->post_date)) . $after;
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.