Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

Wordpress theme - change style for one section of website only?

Options
  • 28-02-2014 9:28am
    #1
    Registered Users Posts: 511 ✭✭✭


    Any recommendations for how best to achieve the following?

    I'm adding a new section to a WordPress site. It's going to differ from the rest of the site, from a style perspective.

    I'm thinking of adding a new template for that section, with a body class=newstyle, or something like that. And then add styles to that class in the css.

    So then, for every page within that section, I just assign the new template.

    Any thoughts on this? Is there an easier or better way to do it?


Comments

  • Registered Users Posts: 6,493 ✭✭✭daymobrew


    If the section is to be radically different and it is made up or pages (instead of posts) you can create a new page template and set each page to use that template.

    Either way, I recommend using the body_class() function in your 'body' tag to allow you target individual pages or posts or groups of the same in CSS.

    On a post on one of my sites the body_class() call generates this code:
    [html]<body class="single single-post postid-137 single-format-standard logged-in admin-bar no-customize-support post-quirky-help gecko alt-style-default one-col width-960 one-col-960">[/html]
    I have code that adds the post slug to the list:
    [php]// Add page/post slug to body class.
    // From: http://www.wpbeginner.com/wp-themes/how-to-add-page-slug-in-body-class-of-your-wordpress-themes/
    function add_slug_body_class( $classes ) {
    global $post;
    if ( isset( $post ) ) {
    $classes[] = $post->post_type . '-' . $post->post_name;
    }
    return $classes;
    }
    add_filter( 'body_class', 'add_slug_body_class' );[/php]
    You can add the post categories too.

    With these classes in the body tag, you can then target them in the stylesheet.


  • Registered Users Posts: 511 ✭✭✭D Hayes


    Super stuff - just what I was looking for. Thanks, daymobrew.


  • Registered Users Posts: 65 ✭✭akagaby


    or you could just install a new wordpress in a new folder (wink wink)


  • Registered Users Posts: 6,493 ✭✭✭daymobrew


    akagaby wrote: »
    or you could just install a new wordpress in a new folder (wink wink)
    In the Lego Movie trailer the main character builds a double decker couch. What did the other two characters say of it? :D


  • Registered Users Posts: 65 ✭✭akagaby


    :)


  • Advertisement
Advertisement