Welcome to the Treehouse Community
The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.
Pieter Van Looy7,763 Points
Don't we have to print out our sidebar's in the sidebar template files, but putting the code get_sidebar() ?
I don't see the code to print out our sidebar's. How does WP knows which sidebar to print and where to print?
Liam ClarkeTreehouse Moderator 19,877 Points
the get_sidebar function gets the file sidebar.php by default.
If you had multiple sidebars you would name them with the prefix of sidebar and then pass in the parameter of the sidebar name.
in my project i have 2 sidebars.
one is the default and one is for the search page.
so i add 2 files.
sidebar.php sidebar-search.php // This can be called anything as long as it starts with sidebar.
<?php // in my index.php get_sidebar(); // This will just get the default sidebar
<?php // In my search.php get_sidebar( 'search' ); // now wordpress knows to look for a file that starts with sidebar and ends in search, seperated by a hyphen ( - )
Hope this helps