treehouse : what would you like to learn today?
Web Design Web Development iOS Development

Target pages in Wordpress?

  • How can I target pages with CSS in Wordpress. I would like to spec different styles in the index.php, single.php, archive.php etc.

    Those pages don't have a unique opening body tag.
  • Have you set up your body tag like this:
    <body <?php body_class(); ?>>

    Because that will spit out all of the selectors you could need.
  • YES!

    How do I get started? I know very little about php.
  • Find your header.php file, that's where you should have the body tag.

    Simply replace:
    <body>

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

    And check the results on your website.
  • Do I have to target the whole class?
    <body class="archive category category-marketingbytes logged-in">

    or can I just use archive or single etc.?
  • You can target whichever you like!

    If you want to target the category "marketingbytes", for example, you could do this in your css:
    .category-marketingbytes #wrapper #content a {
    color: blue; /* Marketing Bytes links will be blue! */
    }
  • What about just "archive" or "single?"

    .archive h2 {}
  • That would work fine, too.

    So '.archive h2' would target all h2's within any archive page.

    single.php is used for posts, page.php is used for pages, etc etc.
  • That's great. Thank you!