• Resolved SALi2013

    (@sali2013)


    Hello, with huge thanks for an amazing theme and previous advice given, I’m back struggling to get my site looking right and would be really grateful for a little more advice from experienced members.

    I’m using Hueman 2.1.9 with child theme.

    I have added different image backgrounds (tiled/repeat) for each page using:

    .page-id-1{
            background-image: url('https://sitename.co.uk/location/filename.gif') !important;
    	background-repeat:repeat;

    and a background image for each category using:

    body.category-categoryname {
    	background-image: url('https://sitename.co.uk/location/filename.gif');
    	background-repeat:repeat;

    And whilst theres a lot of css it does seem to work.

    However posts assigned to the categories do not show the relevant category background.
    Posts will not have multiple categories so is there anyway I can achieve this? i.e.. posts in Category1 will all share the Cat1 background.
    Although a novice I am trying to minimise my use of plugins.

    After searching and experimenting without success any advice would be really appreciated. Thank you all.

    saransons.co.uk

Viewing 11 replies - 1 through 11 (of 11 total)
  • Hi SALi2013. Let us know when your site is back online and we’ll take a look. Thanks.

    Thread Starter SALi2013

    (@sali2013)

    Thank you. The site is now online, I had to take a break from it for a while. There is only one test post published (Hello World) which when viewed doesn’t have the background of its category.

    If there is a relatively simple solution I would like to continue aiming for each section (category and its pages or posts) distinguished by a background unique to that topic. However if this is likely to be beyond my abilities or you advise against this as it may cause other issues, I will have to rethink a combined background that works for the entire site. I am starting to wonder if perhaps the pages are loading more slowly?

    Thank you again.

    Do you have another test site we should be checking? The link you provided above looks like an active site with more than one post. Also, just a side note; you might consider updating your theme to the latest version 2.2.2.

    Thread Starter SALi2013

    (@sali2013)

    Thank you, I will update the theme tonight, I hadn’t even realised there was a newer version. I’ve just disabled the maintenance mode and the link seems to be working ok for me, but sorry please see if this works: Saransons

    So far I’ve uploaded the red Saransons header, created the menu with my categories and subcategories and given them backgrounds, but I can’t seem to get the posts to display with the same background as the category they are assigned to.

    The problem with my novice ‘try some code and see if it works’ method, is that whether it goes right or wrong I just haven’t a clue why.

    OK, that link worked. Are you trying to get the entire center content area to display the category background? Or just the post text area? Or some other area? And, your “try some code and see if it works” method isn’t just for novices…;-)

    Thread Starter SALi2013

    (@sali2013)

    Oh good, glad it isn’t just me!
    Its just the web page background (with only the outer edges visible) behind the content that I want to change, nothing within the post itself.

    So the ‘Farm’ category has a blue tin web page background when selected,
    as do the subcategories ‘Wildlife’, ‘Farm Blog’, etc.,
    but any post assigned to those categories will just have the white webpage background when viewed.

    I hope that makes sense. I thought topic-related backgrounds would make the site more attractive and easier for visitors to recognise where they are. But this has been bugging me for a while and I’m starting to wonder if I’m making an issue out of something that won’t even be visible on mobile devices.
    Your honest opinion welcome ??

    Thread Starter SALi2013

    (@sali2013)

    Sorry, that would be better put as…
    *but any post assigned to those categories just has the white webpage background, and I want it to be ‘blue tin’ like the category its been placed in.

    OK, I see the background now. If I understand what you’re asking, you want the page background (i.e. the blue tin) on the single post page to be the same as it is on the category page that the post belongs to. Yes? No?

    Thread Starter SALi2013

    (@sali2013)

    Yes, thats exactly right.
    Is this achievable? As posts can be assigned to more than one category (not that I want to), I wonder if this would create a conflict of backgrounds to display.

    The piece that’s missing is the post category in the body tag. I found this function at css-tricks.com which should do the trick:

    function SALi2013_add_category_to_single($classes, $class) {
      if (is_single() ) {
        global $post;
        foreach((get_the_category($post->ID)) as $category) {
          // add category slug to the $classes array
          $classes[] = $category->category_nicename;
        }
      }
      // return the $classes array
      return $classes;
    }
    add_filter('body_class','SALi2013_add_category_to_single');

    Add that to your child theme functions.php file.
    Then, where you have this css:

    body.category-categoryname {

    Add the post category:

    body.category-categoryname, body.categoryname {

    Not sure about a post having multiple categories since all the post categories would end up in the body tag. The process would pick one of the css selectors, just don’t know which one. You could use the “:not()” pseudo class selector to exclude other categories but that would be a maintenance nightmare. If you keep posts in a single category you should be ok.

    Thread Starter SALi2013

    (@sali2013)

    Apologies for the delay; work beckoned.
    Initially I had some problems; the posts still didn’t match categories and the layout was a little scrambled with various warnings:
    Warning: Missing argument 2 for SALi2013_add_category_to_single() in …/… functions.php on line 11
    class=”home page page-id-xx page-template-default logged-in admin-bar no-customize-support col-3cm boxed safari”>

    However, using the proven ‘try some code and see if it works’ method ?? I have made some changes and can get the post backgrounds to change. Though it still requires extra work to specify the posts/categories I’m very grateful for your assistance yet again. This resolution will also be useful for another more straightforward site I’m creating using the Hueman theme.

    I have also updated the theme and have a few issues (self-inflicted, no fault of the theme) which I’m resolving, but otherwise sincere gratitude for your assistance.

    Thank you!

Viewing 11 replies - 1 through 11 (of 11 total)
  • The topic ‘Custom backgrounds work with cats & pages but not posts?’ is closed to new replies.