Going back to our sidebar

Back in the old days, it was very common for a WordPress site to use statically placed content blocks in the sidebar. In other words, the only way to place dynamic content in the sidebar of our sites was to use handmade code that would fetch whatever data we wanted and then display it. This solution wasn't very usable for everyday users who might not be familiar with the PHP source code. A better solution needed to be found. Hence, widgets.

Widgets give us the ability to set the sidebars in a way so that they fetch the data that's been set in Appearance | Widgets. Therefore, the only thing the user has to do is go to Appearance | Widgets and pick whatever content they want to feature in the sidebar (or any other widget area for that matter; it could be in the footer as well).

Just to give you an example of old versus new, here's what a standard piece of code might look like that handles displaying blog archives the old way (this can be placed in sidebar.php):

<div id="secondary" class="widget-area" role="complementary">
  <aside>
    <h1>Archives</h1>
    <ul>
      <?php wp_get_archives(); ?>
    </ul>
  </aside>
</div><! -  #secondary  - >

However, this code is not customizable in any way, so a much better solution to display the archives is to use the code that we already have in our sidebar.php, which is as follows:

<div id="secondary" class="widget-area" role="complementary">
  <?php if(is_active_sidebar('sidebar-1')) dynamic_sidebar( 
    'sidebar-1' ); ?>
</div><! -  #secondary  - >

Then, just assign a new Archives widget to this sidebar in the Appearance | Widgets section of wp-admin.