Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

WordPress

Pieter Van Looy
Pieter Van Looy
7,764 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?

1 Answer

Hi Pieter

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.

for example:

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

Liam