• So….

    I have gotten to the point where my inside page needs are sufficiently different from the front page that I can’t share the same sidebar. What’s the best way to set up a second sidebar and how can I instruct it to appear on inside pages, not the front page?

    Alternatively, is there some php that I can slap into the existing sidebar.php that says “only show this here if it’s not the front page”? If I do that, would it be a widget? Would it screw up the existing widget concept?

    Thanks!

Viewing 14 replies - 1 through 14 (of 14 total)
  • Create your second sidebar and call it something like sidebar-inner.php. Then replace <?php get_sidebar(); ?> with something like:

    <?php
    if( is_home() || is_front_page() ) get_sidebar();
    else get_sidebar('inner');
    ?>;

    in all relevant template files.

    Thread Starter nickaster

    (@nickaster)

    okay… thanks a lot. One wee problem. My sidebar seems to be entirely generated by widgets. The only code of relevance in sidebar.php is:

    <?php if ( !function_exists('dynamic_sidebar') || !dynamic_sidebar() ) : ?>

    What does this mean? Where is dynamic sidebar coming from? I can’t find it anywhere, but I know that it’s a vertical row of widgets.

    Really, the only thing I’m trying to do is add a certain feature between two of the widgets – ie, a special widget, that only appears on inside pages.

    Maybe there’s a better way to do this? Is is possible to author a widget that ONLY appears on inside pages? Do you know how to go about doing that?

    Thanks!

    Where is dynamic sidebar coming from?

    It’s generated by WP and replaces thee code that comes after the line you quoted above and before the <?php endif;?>.

    You might want to have a look at widget plugins to see if there’s one that will let you exclude, or include, certain pages. Otherwise you’d have to go via the 2 sidebars route described above.

    Thread Starter nickaster

    (@nickaster)

    okay cool… but… if I did the two sidebar method, then how would the widgets get to both sidebars? Ie, if I just cloned one, then I’d still be in the same boat with not being able to insert something new on that second sidebar, right?

    No. If you have 2 sidebars, you can add widgets to them completely independently. WP will call them Sidebar 1 and Sidebar 2 and you’ll see both as separate entities in Admin/Appearance/Widgets.

    I’ve got themes with 5 or 6 widget-capable areas that work independently.

    Thread Starter nickaster

    (@nickaster)

    Okay wow. I didn’t know that was possible! very cool

    SO… I just created a copy of “sidebar.php” and called it “sidebar-inner.php”

    But… now what? If I use the following php on the single.php pages, for example:

    <?php
    if( is_home() || is_front_page() ) get_sidebar();
    else get_sidebar(‘inner’);
    ?>;

    1) How does it know that ‘inner’ means “sidebar-inner.php” ?
    2) How do I get side-bar inner to show up on the widget page where I can drag and drop?

    Thread Starter nickaster

    (@nickaster)

    okay… so I did a little homework and discovered this page – https://www.blogohblog.com/adding-extra-sidebar-to-your-wordpress-theme/

    Very helpful. Trouble is my functions.php file has loads of crap in it. I have no idea what most of it is. The relevant part about registering sidebars looks like this:

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

    So… I vaguely understand that it’s trying to slap that div code around each widget and make the titles h3. But how do I tell it there are 2 sidebars?

    Thread Starter nickaster

    (@nickaster)

    Okay, I give up on understanding that code.

    I can create what appears to be a second sidebar, but is it possible to have the same widget on two sidebars? If I drag on to a new sidebar, it’s unavailable to be on the earlier one. WTF? I can’t believe how hard it is to do ANYTHING with WP without knowing php….ugh…

    But how do I tell it there are 2 sidebars?

    You don’t have to. WordPress will just number them. But if you want to have specific sidebar names or want to have slightly different markup, you can use something like:

    if ( function_exists('register_sidebar') ) {
        register_sidebar(array(
    		'name'=> 'Home',
            'before_widget' => '<div id="%1$s" class="widget %2$s">',
            'after_widget' => '</div>',
            'before_title' => '<h3>',
            'after_title' => '</h3>',
        ));
        register_sidebar(array(
    		'name'=> 'Inner',
            'before_widget' => '<div id="%1$s" class="widget %2$s">',
            'after_widget' => '</div>',
            'before_title' => '<h3>',
            'after_title' => '</h3>',
        ));
    }
    Thread Starter nickaster

    (@nickaster)

    esmi, you rock. I owe you a beer or three.

    final question. – It still looks like I have to make the widgets twice if they happen to be “text – arbitraty HTML and I want them on both sidebars, right?

    Yes. Each sidebar is completely separate, so if you want “Foo” text to appear on both, you have to literally add it to both.

    Thread Starter nickaster

    (@nickaster)

    Okay great. So… the final straw – now I’m trying to get the second sidebar to appear on the single.php page.

    Originally the code looked like this:

    <?php get_sidebar(”); ?>

    I changed it to:

    <?php get_sidebar(‘inner’); ?>

    Nothing whatsoever happens. I could put

    <?php get_sidebar(‘CRAPTASTIC’); ?>

    In there and it still calls up the main sidebar. How the heck to I get this thing to recognize the other sidebar?

    Thread Starter nickaster

    (@nickaster)

    I finally found some random code that worked:

    <?php if ( !function_exists('dynamic_sidebar')
    || !dynamic_sidebar('Inner') ) : ?>
    <?php endif; ?>

    Why did I need to do this? It actually works, except for the fact that the second sidebar does not add <div=”sidebar”> … </div> to the top and bottom – even though it’s exactly the same fucking code as the other one. Yay! This is really no longer fun!

    If I change it to:

    <?php if ( !function_exists('dynamic_sidebar')
    || !dynamic_sidebar('Home') ) : ?>
    <?php endif; ?>

    THen it pulls the original sidebar as expected, but also with the <div=”sidebar”> … </div> stripped out of it.

    What the living *** is making it do that? HOw? WHy? What? Who?

    I slapped the div code around the thing in single.php and everything works, but I know now I’m in dangerous hack territory.

Viewing 14 replies - 1 through 14 (of 14 total)
  • The topic ‘Special Sidebar for Inside Pages’ is closed to new replies.