This is searchable archive of our old support forums, which operated from 2012 - 2016. To find out how to get support for your current theme, please visit our support page.

Multiple stylesheets in one theme

  • Creator
    Topic
  • #1215
    odyn
    Participant

    Just a thought. Many times it would make sense from design point of view to have different colors for different sections of the same webpage. For example a sport institution could have pages connected to basketball in one set of colors, things connected to football in another set of colors, … which could be implemented as more than one instance of style.css (within the same theme of course) and some kind of option choosing among them.

    Alternatively (or as an addition) sometimes it could be useful to have different stylings for the same element. For example I could use more than one post grid within the same custom layout, but each with it’s own background color (or other stylings) to make different sections of the page more separable by the user.

    (am I talking nonsense and this is actually something very easy or impossible to do?)

Viewing 1 replies (of 1 total)
  • Author
    Replies
  • #1218
    Jason Bobich
    Keymaster

    Sure, you could have different styles based on the current page. There are two overall approaches you can take that I can think of.

    1) You could do it server-side by enque’ing whatever stylesheet based on some parameter, possibly a WordPress conditional. —

    http://codex.wordpress.org/Function_Reference/wp_enqueue_style

    http://codex.wordpress.org/Conditional_Tags

    2) Or even without enque’ing any additional CSS files, you can style different pages from your style.css by simply utilizing the body classes the theme and WordPress give you.

    For example, on every page on your site WordPress gives you a unique class attached to the body based on the current page that is page-id-{page_id}.

    .page-id-123 .thing-1 { ... }
    .page-id-123 .thing-2 { ... }
    .page-id-123 .thing-3 { ... }
Viewing 1 replies (of 1 total)
  • You must be logged in to reply to this topic.