2014-02-14 21 views
0

我想打印出類似這樣不能WordPress的

【類別】帖子標題

有了這個代碼與標題打印類別我得到這個錯誤

注意:Trying獲得非對象的財產....

這是電流輸出

[] Olá, mundo! 
array(1) { [0]=> object(stdClass)#2068 (17) { ["term_id"]=> &int(3) ["name"]=> &string(5) "PT-PT" ["slug"]=> &string(5) "pt-pt" ["term_group"]=> int(0) ["term_taxonomy_id"]=> int(3) ["taxonomy"]=> string(8) "category" ["description"]=> &string(0) "" ["parent"]=> &int(0) ["count"]=> &int(1) ["object_id"]=> int(1) ["filter"]=> string(3) "raw" ["cat_ID"]=> &int(3) ["category_count"]=> &int(1) ["category_description"]=> &string(0) "" ["cat_name"]=> &string(5) "PT-PT" ["category_nicename"]=> &string(5) "pt-pt" ["category_parent"]=> &int(0) } } 

謝謝你們!

+1

將$ category [「name」]更改爲$ category [0] - > name –

回答

2
$args = array('numberposts' => '10'); 
    $recent_posts = wp_get_recent_posts($args); 
    foreach($recent_posts as $recent){ 
     $category = get_the_category($recent["ID"]); 
     echo '<li>['. $category[0]->name .'] <a href="' . get_permalink($recent["ID"]) . '" title="Look '.esc_attr($recent["post_title"]).'" >' . $recent["post_title"].'</a> </li> '; 
     var_dump($category); 
    }