Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

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

  • 28-02-2014 09:28AM
    #1
    Registered Users, Registered Users 2 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, Registered Users 2 Posts: 6,677 ✭✭✭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, Registered Users 2 Posts: 511 ✭✭✭D Hayes


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


  • Registered Users, Registered Users 2 Posts: 65 ✭✭akagaby


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


  • Registered Users, Registered Users 2 Posts: 6,677 ✭✭✭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, Registered Users 2 Posts: 65 ✭✭akagaby


    :)


  • Advertisement
Advertisement