I have a layout for http://www.theesperanzacenter.org that I'm working on. Based upon reading in the Codex and other forum posts, I came up with the following function that I had hoped would allow me to have a unique photo for each parent category. However, when I visit the archives of a sub-category, I get the following error:
Catchable fatal error: Object of class WP_Error could not be converted to string in /home/esperanz/public_html/wp-content/themes/thesis/custom/custom_functions.php on line 66
Line 66 of my code refers to creating the photo name plus the category_nicename (ie photo-category-nice-name.jpg).
This is the function that I'm using:
function image_header () {
if (is_home() || is_front_page()) {
$header_photo = "photo-home";
}
elseif (is_search()) {
$header_photo = "photo-search";
}
elseif (is_category() || is_archive() || is_single()) {
$cat = get_the_category();
$category = get_category_parents($cat[0]->category_parent, false, '', true);
$header_photo = "photo-".$category."";
} else {
$cat = get_the_category();
$category = get_category_parents($cat[0]->category_parent, false, '', true);
$header_photo = "photo-".$category."";
}
$header_photo_url = "".get_bloginfo('template_url')."/custom/images/category-headers/".$header_photo.".jpg";
echo ("<img src='."$header_photo_url".'>");
I believe that the function that I've written is only pulling the current (child) category, and not the top level category.
Can anyone offer me some advice?