Support » Fixing WordPress » Unique photo for each parent category

  • I have a layout for 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?

Viewing 7 replies - 1 through 7 (of 7 total)
  • Can anyone give me a little WordPress love on this stumper?

    I’m answering as many noob questions as I can in hopes of someone taking a look!

    I’m having a similar problem, I think it’s get_category_parents(), its output is an object instead a string, I’m looking for a solution too.
    Do you find anything about?
    If not, when I’ll find the answer I’ll write you here.

    I have read again your code and I don’t think we have the same problem.
    Try var_dump($category), to see what is it, or var_dump(any other var), so you can find where is the problem.

    @manitfestcreative, you figure it out yet?

    i am having the same problem and it is caused by incompability of 2.7 and get_category_parents. any solution?

    oh I found it, insert this
    $category = get_the_category();
    $cat = $category[0]->cat_ID;

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Unique photo for each parent category’ is closed to new replies.