2014-03-02 27 views
0

我試圖用一個插件來打印當月的WordPress的頁面。怎樣的PHP函數的輸出功使用print_r的?

function RSB_Archive_Function($atts) { 

    $month = date('M'); 
    $year = date('y'); 

    $args = array(
    'posts_per_page' => 10, 
    'offset'   => 0, 
    'category'   => '', 
    'orderby'   => 'post_date', 
    'order'   => 'DESC', 
    'include'   => '', 
    'exclude'   => '', 
    'meta_key'   => '', 
    'meta_value'  => '', 
    'post_type'  => 'post', 
    'post_mime_type' => '', 
    'post_parent'  => '', 
    'post_status'  => 'publish', 
    'suppress_filters' => true); 

    print_r($month); 


} 

add_shortcode('rsb-archive', 'RSB_Archive_Function'); 

出於某種原因,該月的月「正在打印上面的標題以及在頁面時我插入短碼到網頁?正如在這裏看到:http://www.robotspacebrain.com/archive-coding/

任何想法,爲什麼這個我是這樣嗎?

+0

這與'php'無關,它與你的內容(html)的結構和標記(css)以及何時調用此函數(輸出'print_r'文本)無關。 –

+0

究竟是什麼是你的問題嗎?你是問爲什麼輸出打印在兩個不同的地方而不是一個? –

回答

2

一個簡碼功能應返回的值,而不是輸出。如果沒有第二個參數,print_r輸出時,它就是所謂的價值。

嘗試

return print_r($month, true); 

代替。雖然在這種情況下,我不認爲print_r是必要的;只需返回$month

+0

謝謝,這工作完美。我沒有意識到你必須返回print_r值來抑制輸出。 – RSB

+0

酷;樂意效勞。 – Hobo

相關問題