Viewing 11 replies - 1 through 11 (of 11 total)
  • Thread Starter jawker

    (@jawker)

    bump

    You don’t need a plugin for a widgetized top bar, you just need to set it up in your template.

    Put this in your theme‘s functions.php file (you may already see part of it there…):

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

    and in your header.php or wherever your top horizontal “bar” needs to go:

    <?php if ( !function_exists('dynamic_sidebar') ||
               !dynamic_sidebar('topbar') ) { ?>
         <p>Oops... this displays if the topbar is not set up</p>
    <?php } ?>

    You should see two choices in the Widgets dropdown, sidebar and topbar. You can use whatever names you like, and add more if you want… bottom bar, floating bar, tiki bar… have fun.

    Hi Roger, thanks for this useful tip! Just curious .. do you know what %1$s (the class of the li-element) stands for?

    The %n$s are php placeholders for the printf function. Arguments 1 and 2 represent something the dynamic sidebar system inserts when it generates each widget for that sidebar area at runtime…

    Typically 1 is the unique identifier of the widget, eg “text-1”
    And 2 is the class for the specific widget, eg “widget_text”.

    They allow you to style a particular widget differently using CSS, or do more radical things with jQuery.

    So I don’t recommend changing them. You might consider adding a class (separated by a space) such as “topwidget” if you need to generally style things in that area differently, although there are other ways to do that without adding a class.

    Thank you very much for the info!

    you have an error on your code! an additional } on the first snippet
    thanks! it was very useful

    You mean a { like this:

    if ( function_exists('register_sidebar') )  {

    Awesome stuff, works like a charm ??
    Thank you, Roger!

    thnx roger it worked!!! its cool!!
    but how do i make the widgets next to each other instead below one another??

    thnx

    mikegoodstadt

    (@mikegoodstadt)

    2 Questions about using the code in a child theme of Thematic which is already widgetized.

    1. I only want to add a ‘topbar’ so should I use the following code in to the child’s funtion.php:

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

    And then add the other piece of code just as you wrote it into the child’s header.php.

    2. When I add your code to a child theme funtions.php it pops the new area in at the top of the list. This displaces the widgets ‘owned’ by each area by one as follows:
    BEFORE

    primary aside: categories
    secondary aside: links
    other area: anotherwidget
    etc

    AFTER

    topbar: categories
    primary aside: links
    secondary aside: anotherwidget
    etc

    I am no PHP expert so I am right in thinking that this is caused by the Array command adding the new values in at the _start_ of the existing array?
    Is so an you advise however add the new area at the end of the array?

    Many thanks,
    Mike

    @mikegoodstadt – #1 – yes, you only need to register your topbar if there’s just one.

    #2 – not sure what the issue really is – I probably need a picture – but the array you see is just a way PHP collects and passes all the parameters. ‘topbar’ is the name of the sidebar you’re setting up. The rest is what XHTML to put around the widgets IF they are output.

    On the Widgets page you assign widgets to specific sidebars, then set them up.

    Wherever you call dynamic_sidebar('topbar') it will insert the widgets for that sidebar – ie ‘topbar’. You should usually only call it once for each sidebar, where you need it.

    Some older code fails to name the sidebars; in that case you can fix things by inserting a name in both places – ie dynamic_sidebar() and register_sidebar() – for each of the sidebars. Otherwise, yes, calling dynamic_sidebar() without a string parameter might just output the next sidebar in the order they were defined.

Viewing 11 replies - 1 through 11 (of 11 total)
  • The topic ‘top bar plugin’ is closed to new replies.