WordPress.org

Forums

[resolved] Widget Background (8 posts)

  1. cableghost
    Member
    Posted 4 years ago #

    I found a number of solutions to changing the background color of widgets, but how might I change the widget background only when that widget appears on a specific page ID, or page range?

    -Scott

  2. esmi
    Forum Moderator
    Posted 4 years ago #

    Use the classes generated by body_class().

  3. cableghost
    Member
    Posted 4 years ago #

    Thank you esmi, but I am stuck.

    I see in your example:
    <?php body_class('$class'); ?>

    But how would I attach this to a specific widget, and would I place page ID with $class?

    -Scott

  4. Mark / t31os
    Moderator
    Posted 4 years ago #

    Widgets all have unique IDs, you should be able to target them specifically without needing the body class (although it could be used to do the same).

    Could you link to a page with the widget in question?

  5. cableghost
    Member
    Posted 4 years ago #

    @t31os_ Here is my test site: http://test.9001sites.com

    We could look at the widget named 'Recent Titles' as an example, and have the background color changed only when viewing the VisoDerm post (http://9001sites.com/test/visoderm/)

    -Scott

  6. Mark / t31os
    Moderator
    Posted 4 years ago #

    If you're using the widget in several places you'll need a way to differentiate, in which case, back to the body class (as emsi origianlly suggested)..

    Open up your theme's header.php and find the body tag..

    <body>

    Update that to..

    <body <?php body_class(); ?>>

    Which will then provide us with a definitive class and ID we can use to selectively target that page's recent post widget(although it is in essence the same widget, just on a particular page).

    Add that to the body and post back when you're done, and i'll help you with writing the css.. :)

  7. cableghost
    Member
    Posted 4 years ago #

    Pardon the delay; my test crashed and had to start over ;-)

    I have made the body change as directed.

    -Scott

  8. cableghost
    Member
    Posted 4 years ago #

    I finally figured it out.

    -Scott

Topic Closed

This topic has been closed to new replies.

About this Topic