WordPress.org

Ready to get started?Download WordPress

Codex

Attention Interested in functions, hooks, classes, or methods? Check out the new WordPress Code Reference!

Difference between revisions of "Function Reference/get sidebar"

m (Related: - link to body_class example of get_sidebar)
Line 64: Line 64:
   
 
==Related==
 
==Related==
  +
* [[Function Reference/body_class#Add_Sidebar_Classes|Adding Sidebar Classes included with get_sidebar to body_class]]
 
{{Include Tags}}
 
{{Include Tags}}
 
{{Tag Footer}}
 
{{Tag Footer}}

Revision as of 22:57, 7 October 2011

Description

Includes the sidebar.php template file from your current theme's directory. If a name ($name) is specified then a specialized sidebar sidebar-{name}.php will be included.

If the theme contains no sidebar.php file then the sidebar from the default theme wp-includes/theme-compat/sidebar.php will be included.

Usage

<?php get_sidebar$name ); ?>

Parameters

$name
(string) (optional) Calls for sidebar-name.php.
Default: None

Examples

Simple 404 page

The following code is a simple example of a template for an "HTTP 404: Not Found" error (which you could include in your Theme as 404.php).

<?php get_header(); ?>
<h2>Error 404 - Not Found</h2>
<?php get_sidebar(); ?>
<?php get_footer(); ?>

Left and Right Sidebars

Two sidebars in one theme.

<?php get_header(); ?>
<?php get_sidebar('left'); ?>
<?php get_sidebar('right'); ?>
<?php get_footer(); ?>

The file names for the right and left sidebars should be sidebar-right.php and sidebar-left.php respectively.

Multi sidebars

Different sidebar for different pages.

<?php
if ( is_home() ) :
    get_sidebar('home');
elseif ( is_404() ) :
    get_sidebar('404');
else :
    get_sidebar();
endif;
?>

The file names for the home and 404 sidebars should be sidebar-home.php and sidebar-404.php respectively.

Notes

Change Log

  • Since: 1.5.0
  • 2.5.0 : Added the 'name' parameters.

Source File

get_sidebar() is located in wp-includes/general-template.php.

Related

Include Tags

See also index of Function Reference and index of Template Tags.