WordPress.org

Ready to get started?Download WordPress

Forums

top bar plugin (12 posts)

  1. Jawker
    Member
    Posted 6 years ago #

    hello guys,

    i'm new here. i recently found something very useful that i can use for my site. it adds a top bar to my page. however, the plugin is not free. is there any other similar plugins (or any ways) for me to do that on my site?

    eg: http://www.maxblogpress.com/plugins/msa/

  2. Jawker
    Member
    Posted 6 years ago #

    bump

  3. Roger Theriault
    Member
    Posted 6 years ago #

    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.

  4. cinematic
    Member
    Posted 6 years ago #

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

  5. Roger Theriault
    Member
    Posted 6 years ago #

    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.

  6. cinematic
    Member
    Posted 6 years ago #

    Thank you very much for the info!

  7. Abid Omar
    Member
    Posted 6 years ago #

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

  8. Roger Theriault
    Member
    Posted 6 years ago #

    You mean a { like this:

    if ( function_exists('register_sidebar') )  {
  9. playxchange
    Member
    Posted 6 years ago #

    Awesome stuff, works like a charm :-)
    Thank you, Roger!

  10. prasdude
    Member
    Posted 5 years ago #

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

    thnx

  11. mikegoodstadt
    Member
    Posted 5 years ago #

    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

  12. Roger Theriault
    Member
    Posted 5 years ago #

    @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.

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags