0

I am using the Hueman Theme. What I want to do is that the background of all the posts should change according to the category of the post.

Please suggest something

  • Are you talking about single posts or category posts – Pieter Goosen Jul 4 '14 at 12:04
1

I do not know this theme. But you must use this two functions somewhere:

 get_theme_mod ('background_image', $default);
 set_theme_mod ('background_image', $_category_image_absolute_path);

Maybe, you can define new modification names with this functions. For example, 'backgroud_image_entertainment', 'background_image_storysode', etc. (as is shown in the referred web page) by using set_theme_mod.

set_theme_mod ('backround_image_entertainment', $_category_image_absolute_path);

Then, you should add some functions to introduce the absolute path of each image using set_theme_mod; and lately call the function get_theme_mod according the current category. This code can be useful (whether you find out how to adapt:

function get_background_image_modified () {
   $category = get_the_category();
    // Here it could be added some checking like:
    // * Are we showing all posts of one category?
    // * Are we in a post?
    // * Are we showing by tags?
    // * Are we in the main page?
    // and add more options
   $cat_name = $category[0]->cat_name; // the category of the first post of the list
   $url_default_image = get_theme_mod ('background_image', $aux);
   $url_cat_image = get_theme_mod ('background_image_'.$cat_name, $aux);

 return (isset($url_cat_image))? $url_cat_image : $url_dafault_image);
}

Then, you will need to find where is called the original get_background_image() in your theme, or where is defined, and include your changes. If the function does not exist, then create it, and replace the main function by using the WordPress API to replace functions. I never did it, but it is possible.

Finally, you will need to name the background image files of each category in some way (for example: background-entertainment.jpg), and include the absolute path of each one by using set_theme_mod somewhere (at the very beginning of the theme loading).

I was working on it with another theme, but I did not figure out every thing, yet. It would be easy to make a PlugIn (which still does not exist). Unfortunately, every theme is developed in different way, and there is no an standard scheme to replace such function.

If someone got the definitive solution, please, do feel comfortable to share it. Thanks!!

0

Wordpress usually adds the category as a class in the body/article tag of each page, you can probably style each category with a custom background through that class.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.