Advertisement
Guest User

sidebar quick help

a guest
May 8th, 2013
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2. /**
  3.  * This is what registers any new sidebar ( widgetized area ) and is generally put in your functions.php file. It is often hooked to one of two functions: 'widgets_init' or 'after_setup_theme'
  4.  */
  5.  
  6. function my_sidebars(){
  7.     // We register a sidebar with a name of 'Primary Sidebar' and an id of 'sidebar-1'
  8.     // If you want to add more just repeat the lines of code and make sure you change the 'id'
  9.     register_sidebar( array(
  10.             'name' => 'Primary Sidebar', /* The name of the sidebar. */
  11.             'id' => 'sidebar-1', /* Must be a unique id; this is what gets called by dynamic_sidebar( ) */
  12.             'before_widget' => '<div>', /* The opening tag that comes before any widget */
  13.             'after_widget' => '</div>', /* The closing tag of the widget */
  14.             'before_title' => '<h2 class="rounded">', /* The opening tag for the title of the widget */
  15.             'after_title' => '</h2>',b /* The closing tag for the widget title */
  16.     ) );
  17. }
  18.  
  19. add_action ( 'widgets_init', 'my_sidebars' );
  20.  
  21. // This next part you put in your sidebar.php file
  22. /* Sidebar template */
  23. if ( is_active_sidebar( 'sidebar-1' ) : // checks to see if there are any active widget in the registered sidebar
  24.   dynamic_sidebar( 'sidebar-1' ); // If so the use the sidebar with the id of sidebar-1
  25. else: // If there are no widgets run this instead
  26.   the_widget( 'WP_Widget_Search' ); // Search widget
  27. endif;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement