2012-10-14 22 views
1

我有這個功能,按類別顯示圖像附加圖片:WP基於

/*default thumbnails for posts if no thumbnail is set, based on the selected category*/ 
add_filter('genesis_get_image', 'default_thumb'); 
function default_thumb($output) { 
if(!$output) { 
$default_cat_thumbs = array( 
'now' => 'now.jpg', 
'news' => 'Volleyball-Club_Leipzig.gif'); 
foreach((get_the_category()) as $category) { 
if (array_key_exists($category->slug, $default_cat_thumbs)) { 
$url = 'http://www.mepanorama.com/wp-content/images/'.$default_cat_thumbs[$category->slug]; 
$output = '<img width="120" height="140" src="'.$url.'" class="alignleft" alt="" title="" />'; 
} 
} 
} 
return $output; 
} 

的偉大工程,以顯示我的檔案頁圖像的「現在」,例如類別。喜歡這裏

http://www.mepanorama.com/category/now/

,但我想顯示圖像這一類的帖子,問題是我永久不包括類,所以是有辦法拉類別名稱讓從我的麪包屑說?

例如張貼 http://www.mepanorama.com/180193/test/

+0

[This may help you](http://wordpresshero.com/hacks/category-images-hack.html/)或[也許這個插件](http://coffee2code.com/archives/2004/06/ 27 /插件類別圖像/)。 –

+0

謝謝,但我儘量避免插件,因爲其他功能與我的基本相同。 – Sundance

回答

0

您可以測試後與in_category類別:

if (in_category("now")) : 
    // do stuff 
end 

您還可以使用get_the_category()來檢索所有類別的具體職位。

foreach((get_the_category()) as $category) : 
    echo '<img src="http://www.mepanorama.com/wp-content/images/' . $category->cat_ID . '.jpg\" />'; 
end 

希望有所幫助。