• Hey guys,

    I’ve just been messing around this morning setting up multiple sidebars, which I’m going to populate and serve up to pages using the is_page() conditional. Code below for everyone’s reference:

    functions.php
    register_sidebars(2, array('name'=>'Sidebar %d'));

    index.php & page.php
    // the 2 references sidebar 2 in the widgets panel in your dashboard

    <?php // display sidebar 2 (left sidebar)
    if ( function_exists('dynamic_sidebar') &amp;&amp; dynamic_sidebar(<strong>2</strong>) ) : else : ?>
    <?php endif; ?>

    … now, my problem. Doing it this way has taken away all my list formating; seen previously in the default sidebar setup:

    if ( function_exists('register_sidebar') )
        register_sidebar(array(
            'before_widget' => '<li id="%1$s" class="widget %2$s">',
            'after_widget' => '</li>',
            'before_title' => '<h2 class="widgettitle">',
            'after_title' => '</h2>',
        ));

    I want this back, cause ATM my formating sucks. These are the two pieces of HTML pumped out:

    <!-- conventional sidebar -->
    <div id="sidebar">
      <ul>
        <li id="text-406465381" class="widget widget_text">
          <h2 class="widgettitle">Left sidebar1</h2>
          <div class="textwidget">Left sidebar1</div>
        </li>
      </ul>
    </div>
    <!-- newly generated sidebar -->
    <li id="text-406475901" class="widget widget_text">
      <h2 class="widgettitle">Right sidebar2</h2>
      <div class="textwidget">Right sidebar2</div>
    </li>

    I need to surround this latter chunk of HTML with similar stuff to the first; a < div > and a < ul > ideally, like the HTML output for the conventional sidebar. Obviously there’s gonna be some conflicts with the sidebar IDs, which need to be unique. So factor that in if you can help me out here.

    Still sucks a bit you can’t give more meaningful names to the widgets you drop in though – text-406465381 does suck quite a bit?!

    Thanks in advance.
    L

    PS. Apologies for using the word ‘suck’ copiously in this post, haha.

Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter ldexterldesign

    (@ldexterldesign)

    There must be a better way of doing this, but this does the job:

    index.php & page.php

    <?php // display sidebar 2 (left sidebar)
    $numberOfSideBarToLoadIn = 2;
    echo "<div id='sidebar" . $numberOfSideBarToLoadIn . "'><ul>";
    if ( function_exists('dynamic_sidebar') &amp;&amp; dynamic_sidebar(2) ) : else : ?>
    echo "</ul></div>";
    <?php endif; ?>

    Dual sidebars – happy days!

    Just gotta find a solution on how to give the sidebars meaningful names, that associate them to the site pages, so the client can chop and change sidebar content in the widget pane.

    Thread Starter ldexterldesign

    (@ldexterldesign)

    Thought I’d update this post. I finally got the result I was looking for. The above comment does work, but it wraps the whole of the post in the sidebar ID giving you something like this, and it will skew your styling badly:

    <div id="header"></div>
    <div id="sidebar2">
      <div id="content"></div>
      <div id="footer"></div>
    </div>

    My solution:

    functions.php

    // display second sidebar
    register_sidebars(2, array('name'=>'Sidebar %d'));

    index.php & page.php etc

    // place in the file where you want your second sidebar to appear in the hierarchy of your mark-up
    <?php // display second sidebar
     include (TEMPLATEPATH . '/sidebar2.php'); ?>

    sidebar2.php

    // i've named the file sidebar2.php for want of a better name. obviously duplicate this piece of code and use 3, 4, 5... to generate a new sidebar
    <div id="sidebar2">
      <ul>
        <?php if ( function_exists('dynamic_sidebar') &amp;&amp; dynamic_sidebar(<strong>2</strong>) ) : else : ?>
        <?php endif; ?>
      </ul>
    </div>

    I plan to load in specific sidebar content on different pages to offer up users contextual information across the website, so just create a load of configured sidebars in your dashboard and serve them up with conditionals from your sidebar2.php file.

    Hope this helps someone somewhere down the line :]

    L

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘I want my list formating back! (dual sidebars)’ is closed to new replies.