2016-05-19 21 views
0

在ThemeKraft簡單主題(Wordpress)中,_tk_posted_on()函數存在問題。 我是初學者,我會說,但我需要一段代碼幫助:_tk_posted_on() - 整個日期而不是年份

function _tk_posted_on() { 
$time_string = '<time class="entry-date published" datetime="%1$s">%2$s</time>'; 
$time_string = sprintf($time_string, 
    esc_attr(get_the_date('c')), 
    esc_html(get_the_date()) 
); 

    $time_string = sprintf('<a href="%1$s" title="%2$s" rel="bookmark">%3$s</a>', 
     esc_url(get_permalink()), 
     esc_attr(get_the_time()), 
     $time_string 
    ); 

    if (get_the_time('U') !== get_the_modified_time('U')){ 
     $time_string_update = '<time class="updated" datetime="%1$s">%2$s</time>'; 
     $time_string_update = sprintf($time_string_update, 
      esc_attr(get_the_modified_date('c')), 
      esc_html(get_the_modified_date()) 
     ); 
     $time_string_update = sprintf('<a href="%1$s" title="%2$s" rel="bookmark">%3$s</a>', 
      esc_url(get_permalink()), 
      esc_attr(get_the_time()), 
      $time_string_update 
     ); 
     $time_string .= __(', updated on ', '_tk') . $time_string_update; 
    } 

printf(__('<span class="posted-on">Posted on %1$s</span>', '_tk'), 
    $time_string, 
    sprintf('<span class="author vcard"><a class="url fn n" href="%1$s" title="%2$s">%3$s</a></span>', 
     esc_url(get_author_posts_url(get_the_author_meta('ID'))), 
     esc_attr(sprintf(__('View all posts by %s', '_tk'), get_the_author())), 
     esc_html(get_the_author()) 
    ) 
);} 

它張貼整個日期和誰發佈的帖子,我希望它僅發佈一年。我已經試過編輯..但我解決不了.. 感謝您的幫助:)

+0

我什麼都不知道WordPress的,但你可以試試這個。我認爲在'esc_attr(get_the_date('c'))'中,c是如何顯示日期的說明符。你的時間是這樣嗎(\t 2004-02-12T15:19:21 + 00:00)?我認爲你正在尋找說明符'Y'。只需用'Y'代替'c'即可解決問題。本網站爲您提供有關不同格式的信息。 (https://codex.wordpress.org/Formatting_Date_and_Time)。 PS。我不敢將此作爲答案發布,因爲我是一個100%的WordPress新手(甚至不是初學者)。如果它解決了,我會把這個答案。 – BramMooij

+0

我自己解決了,謝謝你的幫助.. – s4ddly

+0

好聽。您能否將解決方案作爲答案發布,以便具有相同問題的其他人也可以從中學習? – BramMooij

回答

0
function _tk_posted_on() { 
    $time_string = '<time class="entry-date published" datetime="%1$s">%2$s</time>'; 
    $time_string = sprintf($time_string, 
     esc_attr(get_the_date('c')), 
     esc_html(get_the_date(Y)) 
    ); 

    $time_string = sprintf('<a href="%1$s" title="%2$s" rel="bookmark">%3$s</a>', 
     esc_url(get_permalink()), 
     esc_attr(get_the_time()), 
     $time_string 
    ); 

    printf(__('<span class="posted-on">%1$s</span>', '_tk'), 
     $time_string, 
     sprintf('<span class="author vcard"><a class="url fn n" href="%1$s" title="%2$s">%3$s</a></span>', 
      esc_url(get_author_posts_url(get_the_author_meta('ID'))), 
      esc_attr(sprintf(__('View all posts by %s', '_tk'), get_the_author())), 
      esc_html(get_the_author()) 
     ) 
    ); 
} 

有ü去,這個功能只顯示年份^^

相關問題