Bummer! This is just a preview. You need to be signed in with a Basic account to view the entire video.
Start a free Basic trial
to watch this video
In this last video of the stage we look at including a sidebar.php file as well as look the widget code commonly found in sidebar templates.
-
0:00
The next file we'll look at, is sidebar.php.
-
0:04
Which gets called by the function get underscore sidebar.
-
0:09
It's most common in sidebars to display widget information.
-
0:14
When you display widgets in a theme,
-
0:16
you could also display backup information to show up, if those widgets are not set.
-
0:21
Which is what we're doing in this case.
-
0:25
It is also common to hard code information into the side bar,
-
0:29
that you don't need to provide the user ability to access or edit.
-
0:34
Remember though, the more you hard code in,
-
0:37
the more you'll have to change yourself, and someone cannot do from the admin area.
-
0:43
One place where you may have to make this distinction is,
-
0:46
whether it's best to use a plugin or a widget, or, hard code some widget or
-
0:52
feature that you need featured in the sidebar,
-
0:55
outside of the WordPress admin area, and just directly in this template.
-
1:00
One thing that's important to know about sidebar,
-
1:03
is that you could call it a couple different ways,
-
1:06
similar to the way you would use a get template part function.
-
1:11
If we look in our frontpage.php file,
-
1:14
which we'll get to a bit later, we can see the call get sidebar.
-
1:19
This will load sidebar.php.
-
1:22
However, if we come into our home.php file,
-
1:28
and we scroll down, we can see, Get Sidebar Blog.
-
1:34
This is telling it to find a file called sidebar-blog.php.
-
1:40
[BLANK_AUDIO]
-
1:43
This shows off WordPress' ability to use the get Sidebar function with
-
1:49
a parameter to have custom named or additional sidebar files.
-
1:55
The same is also true for headers and
-
1:57
footers, although they're less commonly used in that way.
-
2:02
Because we have the side bar set up,
-
2:04
and the appropriate code in our functions.php file.
-
2:11
Then, on the backend of our site, we can manage our widgets.
-
2:18
And have them displayed differently depending on what page or
-
2:21
what site we're on.
-
2:24
So, we can come in to here to edit our widgets, and
-
2:27
control what's displaying in the main sidebar versus just in the blog sidebar.
You need to sign up for Treehouse in order to download course files.
Sign up