StudioPress Community Forums

StudioPress Community Forums (http://www.studiopress.com/support/index.php)
-   General Discussion (http://www.studiopress.com/support/forumdisplay.php?f=7)
-   -   Image by category (http://www.studiopress.com/support/showthread.php?t=120805)

sundance 10-13-2012 10:25 PM

Image by category
 
Hi, I found this great function on this forum :

Quote:

/*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;
}
works great to show images in my archive page for category "now" for example. like here

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

but i want to show image for this category in posts, the problem is that my permalink does not include category , so is there is a way to pull the category name lets say from my breadcrumb?

example post
http://www.mepanorama.com/180193/test/

NicktheGeek 10-22-2012 10:53 AM

You can use the get_the_category function to get the required info
http://codex.wordpress.org/Function_...t_the_category


All times are GMT -5. The time now is 04:06 PM.

Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.