StudioPress Community Forums
  StudioPress Community Forums > Forums > General Discussion
For help and support, access to your downloads, or to manage your account please log into My StudioPress.

These forums have been set to read-only so you can browse the existing topics for any questions you may have.

For general discussion on WordPress, CSS and design (NOT for support) visit the new Community Forums.
 
 
Thread Tools Display Modes
  #1  
Old 10-13-2012, 10:25 PM
sundance sundance is offline
Registered User
Genesis Member
 
Join Date: Nov 2011
Posts: 66
Default 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/
  #2  
Old 10-22-2012, 10:53 AM
NicktheGeek's Avatar
NicktheGeek NicktheGeek is offline
Forum Manager
 
Join Date: Feb 2010
Posts: 62,650
Default

You can use the get_the_category function to get the required info
http://codex.wordpress.org/Function_...t_the_category
__________________
Nick "Fred and/or George Weasley" Croft
Designs by Nick the Geek
@Nick_theGeek on Twitter

Make web design easier, get FireBug for FireFox

Want to learn more about Genesis? Check out my Genesis Explained Series

 

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Category w/Image mcroy1 General Discussion 6 05-09-2009 08:49 PM


All times are GMT -5. The time now is 11:39 AM.

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