How to Use Multiple Widgetized Sidebars on WordPress

The widgets on WordPress allow you to easily add dynamic content with minimal effort or the hassle of hand-editing HTML and PHP. However, the default widget setup only allows you to create a single sidebar which may not be applicable on every page or section of your website or blog. By editing a few PHP pages, you can enable multiple widgetized sidebars and specify exactly where each sidebar will appear. Doing so enables you to provide your visitors with more relevant content on each page or post.

Instructions

  1. Enabling Widgets

    • 1

      Open the file \"functions.php\" from your current theme's folder in your WordPress dashboard by clicking \"Appearance\" and \"Editor,\" if the file permissions allow you to edit files in the dashboard.<br /><br />Otherwise, open your FTP client and enter your host name, username and password to connect to your host. Navigate to the directory of your current them which is in the \"themes\" directory, inside the \"wp-content\" directory. Right click \"functions.php\" and select the \"Edit\" option to open in your text editor.<br /><br />If you do not have a functions.php, create a new file in your text editor and save it as functions.php. Upload it to your theme's folder via FTP.

    • 2

      Add the following code to register (multiple) sidebars. <br /><br /><?php<br />if ( function_exists('register_sidebar') )<br />register_sidebar(array('name'=>'Sidebar',<br />'before_widget' => '<li id=\"%1$s\" class=\"widget %2$s\">',<br />'after_widget' => '</li>',<br />'before_title' => '<h2 class=\"widgettitle\">',<br />'after_title' => '</h2>',<br />))<br />GO<br />register_sidebar(array('name'=>'Sidebar2 ',<br />'before_widget' => '<li id=\"%1$s\" class=\"widget %2$s\">',<br />'after_widget' => '</li>',<br />'before_title' => '<h2 class=\"widgettitle\">',<br />'after_title' => '</h2>',<br />))<br />GO<br />register_sidebar(array('name'=>'Sidebar3 ',<br />'before_widget' => '<li id=\"%1$s\" class=\"widget %2$s\">',<br />'after_widget' => '</li>',<br />'before_title' => '<h2 class=\"widgettitle\">',<br />'after_title' => '</h2>',<br />))<br />GO<br />?><br /><br />If you were already able to use widgets on your sidebar, the first portion of code will already exist in your functions file. Repeat the code--from \"register_sidebar\" to \"));\"--for each sidebar you want to register. If your functions file contains other PHP functions, include the code for multiple sidebars immediately after the initial sidebar code.<br /><br />The example above registers 3 sidebars total, titled \"Sidebar\", \"Sidebar2\" and \"Sidebar3\". You can change the names of the sidebar as you see fit. You can registers fewer or greater than 3 multiple sidebars.

    • 3

      Save your functions file in your dashboard or in your text editor. If using an FTP client, upload according to the program instructions.

    • 4

      Add the code to call a sidebar into your theme files. Typically, you include this code in \"sidebar.php,\" which is also located in your current theme's folder. Add the following code at the beginning of your sidebar document, before the traditional sidebar HTML (WordPress will display the traditional HTML if you do not set up widgets in your dashboard). Make sure to change \"Sidebar Name\" to the name of your sidebar (\"Sidebar1\" or \"Sidebar2,\" for example).<br /><br /><?php if ( !function_exists('dynamic_sidebar') || !dynamic_sidebar(Sidebar Name) ) : ?><br /><br />In some WordPress themes, this code may work after the first <ul> tag in \"sidebar.php.\" <br /><br />Paste the following PHP tag at the end of the document to close the code:<br /><br /><?php endif; ?><br /><br />In some WordPress themes, this code may need to appear directly before the closing </ul> tag. Save (and upload) your \"sidebar.php\" to see if the widgetized sidebar appears in the correct place. You may need to move the dynamic sidebar codes up or down several lines to correctly display a widgetized sidebar.<br /><br />You may add the code to other theme files such as \"page.php\" or \"single.php,\" if you understand the WordPress code. On these pages, you can add the code as one block:<br /><br /><?php if ( !function_exists('dynamic_sidebar') || !dynamic_sidebar('Sidebar Name') ) : ?><br /><?php endif; ?> <br /><br />You can use this code multiple times in the same document to call multiple dynamic sidebars as long as you specify \"Sidebar Name.\"

    • 5

      Log in to your WordPress dashboard and access the \"Widgets\" page under \"Appearance.\" Drag-and-drop widgets (such as a calendar, tag or text widget) onto your sidebars as you desire. Save the widgets.<br /><br />You will now see widgetized sidebars on your WordPress blog.

Tips & Warnings

  • You cannot edit WordPress files such as \"function.php\" or \"page.php\" within the WordPress dashboard unless the \"themes\" folder has permissions of 777. To set these permissions, right-click the folder in FTP and select \"Permissions\" or \"CHMOD.\" Type in \"777.\"

Related Searches:

References

Comments

You May Also Like

Related Ads

Featured