50 | Page Template Sidebar Overwrite Theme Options in Twenty Eleven

g+
example of left and right sidebars in static pages of Twenty Eleven

Sidebar on the left or on the right within one Twenty Eleven child theme

Twenty Eleven already comes with a page template to add a sidebar to static pages. However, this sidebar will always be on the same side as the sidebar on the front  page, ruled by the ‘theme options’.
On some pages, you might want to show the sidebar on the opposite side.
This freedom of choice is possible with some special page templates and some coding in functions.php of the theme.

The following codes refer to a child theme of Twenty Eleven.

If you don’t want to follow the steps outlined in the Codex, you can download a ready-made child theme from quirm.net.

First step: in your child theme folder, create two new page templates – one for a fixed sidebar on the left, and the other for the sidebar on the right.

To begin with, copy the code of sidebar-page.php, and save it as sidebar-left-page.php and sidebar-right-page.php, resp.

The file names are important as they refer to the same names in the code for functions.php.

Second step: Change the line ‘ * Template Name: Sidebar Template’ to ‘ * Template Name: Left  Sidebar Template’ and ‘ * Template Name: Right Sidebar Template’, resp.; save the files.

Third step: add the following code to functions.php of your child theme:

function twentyeleven_child_pagetemplates_body_classes( $wp_classes, $extra ){

  $classes = array();

  if( is_page_template( 'sidebar-left-page.php' ) ) :
  // correction for the Left Sidebar Template
    $classes[] = 'left-sidebar';
    $blacklist = array('right-sidebar','singular');
    // Filter the body classes
    foreach( $blacklist as $val ) {
      if (!in_array($val, $wp_classes)) : continue;
      else:
      foreach($wp_classes as $key => $value) {
        if ($value == $val) unset($wp_classes[$key]);
      }
      endif;
    }
  endif;

  if( is_page_template( 'sidebar-right-page.php' ) ) :
  // correction for the Right Sidebar Template
    $classes[] = 'right-sidebar';
    $blacklist = array('left-sidebar','singular');
    // Filter the body classes
    foreach( $blacklist as $val ) {
      if (!in_array($val, $wp_classes)) : continue;
      else:
      foreach($wp_classes as $key => $value) {
        if ($value == $val) unset($wp_classes[$key]);
      }
      endif;
    }
  endif;

return array_merge($wp_classes, (array) $extra, $classes );
}

add_filter( 'body_class', 'twentyeleven_child_pagetemplates_body_classes', 20, 2 );

That code will correct the body_classes of the theme, which are central to the layout of your site.

Finished.

Now you will have two more page templates available in the ‘page attributes’ section when you create or edit a static page.

The sidebar position of these pages will be independant of the theme options (as long as one of the ‘content with sidebar’ options is ticked).

This entry was posted in Tips & Tricks, Twenty Eleven, WordPress and tagged , , , , . Bookmark the permalink.

32 Responses to Page Template Sidebar Overwrite Theme Options in Twenty Eleven

  1. Saundra comments:

    Moisture may freeze at the expansion valve, giving some of the indication of under charging.
    It does not require acidic agent for the reaction to take place and is commonly used
    with neutral-tasting ingredients, such as milk.
    With so many options available, you should be able to find and ship models according to your individual needs without much trouble.

    My website: fiberglass uline marine refrigerators

  2. Ezekiel comments:

    Definitely believe that that you said. Your favorite
    reason appeared to be on the web the easiest thing to consider of.
    I say to you, I certainly get annoyed while other folks think about concerns that they just do not understand about.
    You managed to hit the nail upon the top as neatly as outlined
    out the whole thing with no need side effect
    , folks could take a signal. Will likely be again to get more.
    Thanks

    Review my webpage … high school story cheats youtube

  3. Peggy comments:

    This web site ɗefinitely Һas all of the
    information I wanted about this subject and didn’t ҝnow who to asƙ.

    นอกจากนี้เยี่ยมชมของฉันบล็อก…คอนแทคเลนส์

  4. Dora comments:

    Hi there! Quick question that’s totally off topic.
    Do yoou know how to make your site mobile friendly?
    My weblog looks weird when viewing from my iphone4.
    I’m trying to find a theme or plugin that might be
    able to resolve this problem. If you have any recommendations,
    please share. Wiith thanks!

    my webpage … Clash of Clans Hack Tool

  5. Sylvester comments:

    That is really interesting, You’re an excessively professional blogger.
    I’ve joined your feed and sit up for searching for more of your magnificent post.
    Additionally, I’ve shared your site in my social networks

    My web site – how to get pregnant now in hindi

  6. Allan comments:

    Everything is very open with a clear description of the issues.
    It was definitely informative. Your website is extremely
    helpful. Thank you for sharing!

    Feel free to surf to my weblog :: personal injury lawyer Oakland

  7. Augustus comments:

    If you have a loved one in a nursing home and you suspect
    that there may be abuse or neglect, it may be time to
    step in and call on a nursing home abuse lawyer.
    If you realize this upfront, you will be prepared for the long haul.
    Personal injury attorneys specialize in these types of cases.

    My homepage … Personal Injury Attorney Newport Beach

  8. Carri comments:

    Thank you, I’ve recently been looking for information about this
    subject for a long time and yours is the best I have found out
    till now. However, what in regards to the bottom line?
    Are you certain concerning the supply?

    Feel free to surf to my page: auto air conditioning

  9. Ronda comments:

    You need to take part in a contest for one of the finest websites on the net.

    I will recommend this web site!

    My site garcinia mangostana l

  10. Clay comments:

    The other limo might have a smaller total dollar amount for 3 hours, does not include the driver gratuity and charges on a point-to-point
    basis. Since a wedding is about elegance, the couple should
    consider the image and reputation of each of the company’s they have selected.

    You can choose to have a limousine take you and
    your friends for a night on the town with no worries about drinking and driving.

    Review my web site – limo service wrentham (Clay)

  11. Meredith comments:

    Appreciate this post. Let me try it out.

    Look at my page … Quest Bars

  12. Randolph comments:

    People to facilitate their services, flexibility and immediate availability that offer these services because of the use
    every day. Compare free instant online moving quotes and pick the best moving company based on services & price.
    You can find out about reputed movers and packers companies from
    your area with the help of various websites which enlist movers and packers.

    My web blog: olympian moving and storage phoenix az

  13. Leora comments:

    bener banget, memang kaya gitu gan :)makasih infonya gan, untung nemu ini blog

    my webpage :: film semi full

  14. Florine comments:

    I have to thank you for the efforts you have put in writing this website.
    I really hope to see the same high-grade blog posts from you in the future
    as well. In fact, your creative writing abilities has encouraged me to get my own, personal blog now
    ;)

    my blog post … art experts inc review ripoff reports and complaints (8to18.com)

  15. Kisha comments:

    We aren’t too sure about that — but to be fair we can’t
    exactly argue that the knife handle isn’t incredibly ergonomic (as well as it being designed to be ambidextrous so that it can be used comfortably by almost any chef).
    As we all know that many of the fresh herbs and spices used in Thai cooking – such as
    turmeric, galangal, coriander, lemongrass, and fresh chillies – have immune-boosting and disease-fighting power.
    Loook for one that is large enough for all your knives and consider getting a block that includes a
    place for your kitchedn shears aand for your honing steel.

    My web-site :: Best Kitchen Knife (Cheftalks.Tumblr.Com)

  16. Kristofer comments:

    Do you mind if I quote a couple of your posts as long as I provide
    credit and sources back to your weblog? My website is in the very same area of interest as yours and my visitors would certainly benefit from some of the information you provide here.
    Please let me know if this okay with you. Cheers!

    Feel free to visit my blog :: i love marketing frank kern

  17. Shayne comments:

    Keep on writing, great job!

    Here is my weblog spy software On Htc

  18. Bebe comments:

    It’s actually a great and useful piece of information. I’m
    glad that you simply shared this useful information with us.
    Please stay us up to date like this. Thanks for sharing.

    Feel free to visit my web site mobile spyware

  19. Cory comments:

    There are now select plastic surgeons that offer affordable payment
    plans on their plastic surgery procedures for their clients.
    Some of the popular cosmetic surgery procedures – notably the head lift
    - are popular attributable to aging skin circumstances accelerated by experience of the sun.
    Some proper money movement and a breakaway from the Dolphins could land the tackle in an offense far better suited
    for his talents.

    Here is my blog post; facial plastic surgeon fort lauderdale

  20. Minerva comments:

    I think this is one of the most important info for me.

    And i am glad reading your article. But wanna remark on some general things, The site style
    is perfect, the articles is really excellent : D. Good job, cheers

    My web blog bad credit car dealers orlando FL

  21. Alton comments:

    This open space provides a well-lit gathering spot for
    entertaining. A kitchen must provide an efficient working place, even while it
    looks good. In point of fact, you happen to be informed not to paying for any cooking area redecorating yourself.

    Take a look at my blog post – boca raton plumbers

  22. Linette comments:

    Hello there, You have done an excellent job.
    I’ll definitely digg it and personally recommend
    to my friends. I’m sure they will be benefited from this website.

    Here is my homepage: lifehacks

  23. Lupe comments:

    Great delivery. Outstanding arguments. Keep up the
    good effort.

    My website … Bonati Institute

  24. Samuel comments:

    In 2006, a similar case was presented in Saint Louis. If one has been playing any sports for several years,
    their jersey collections are increasing. I have purchased some replica Minnesota Twins jerseys.

    my weblog stitched jerseys cheap

  25. Audrey comments:

    What’s up to every one, the contents existing at this site are
    actually amazing for people experience, well, keep up
    the good work fellows.

    my webpage; licking the air

  26. skatebarnin comments:

    Thanks Alchymyth, This worked perfectly for me.

  27. Monpelaud comments:

    I created a page template as you described above in my child theme of Twenty Eleven.
    It works fine for the position of the sidebar but styles modified in the style.css of my child theme are not taken into account like for the other pages.
    For example margins are not the same as the others pages.
    How can I resolve the issue ?

    Many thanks for your help.

    • alchymyth replies:

      this will depend on what edits you have made to your page styles. the coding does not do any formatting, i.e. any styles should actually not get effected by the code.
      please join the WordPress.org support forum, and ask the question there. you will likely need to post a link to your site, to a page with the problem, to illustrate what you have so far.

  28. Lisa comments:

    Could you please tell me WHERE in the functions.php file I need to insert this code?

    • alchymyth replies:

      you can add the code basically anywhere in functions.php of the child theme – just don’t break the php syntax; safest is possibly just before the closing php tags ?> at the bottom of functions.php

  29. Lorynne comments:

    Thanks for this tut. could you tell me how you could omit the sidebar altogether?So just as you’ve made the templates above with sidebars on the left or right. How could you include a template that had no sidebar at all?

Leave a Reply

Your email address will not be published.

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>