Support » Themes and Templates » Widget problem

  • Hi,
    I want that my sidebar is supporting widgets.
    This is the code of the html markup:

    <div class="sidebar-head"><h3></h3></div>
    <div class="sidebar-content"></div>
    <div class="sidebar-footer"></div>

    so i tired using the tutorials and came to this php code:

    <?php
    if ( function_exists('register_sidebar') )
    register_sidebar(array(
    'before_widget' => '<div class="sidebar-content">',
    'after_widget' => ' </div>
        <div class="sidebar-footer"></div>',
    'before_title' => '<div class="sidebar-head">
    <h2>',
    'after_title' => '</h2></div>',
    ));
    ?>

    But it doesnt work what is wrong?
    please help me

Viewing 10 replies - 1 through 10 (of 10 total)
  • The code in your sidebar should look something like:

    <div class="sidebar-head"><h3></h3></div>
    <ul class="sidebar-content">
    <?php if ( !function_exists('dynamic_sidebar') || !dynamic_sidebar() ) : ?>
        <!-- What happens if you don't have the widgets functionality. Static widgets for example. -->
    <?php endif; ?>
    </ul>
    <div class="sidebar-footer"></div>

    Then, in the functions.php file:

    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>',
        ));

    And that should do it.

    but thats html code is one element of the sidebar.
    every widget should look like this.
    you know what i mean?

    oh… I thought that whas the whole sidebar… Hmmm… Since the widget title gets echoed inside the widget and not outside as in your code…

    if ( function_exists('register_sidebar') )
        register_sidebar(array(
            'before_widget' => '<div class="sidebar-head">',
            'after_widget' => '</div>
    <div class="sidebar-footer"></div>',
            'before_title' => '<h3>',
            'after_title' => '</h3></div>
    <div class="sidebar-content">',
        ));

    But you’re probably going to have problems with widgets that don’t have a title, like the search widget.

    mhm damn it dowsnt work. Do you have an e-mail so i can show you the link to the theme
    greetz

    http://wpguy.com/contact 😉 I don’t want to get spammed by everyone 😀

    *spams the contact form*

    lol >:-O

    I have a similar question to sensifreak. I can add widgets to my page at the moment using the dashboard but instead of adding them to my normal sidebar somewhere like I want it puts them in instead/over my sidebar.

    The code for my sidebar is

    <div id=”sidebar”>

      <?php if ( !function_exists(‘dynamic_sidebar’) || !dynamic_sidebar() ) : ?>
      <?php wp_list_pages(‘title_li=<h2>Pages</h2>’ ); ?>

    • <h2>Archives</h2>
        <?php wp_get_archives(‘type=monthly’); ?>
    • <h2>Calendar</h2>
      <?php get_calendar(1); ?>
    • <h2>Categories</h2>
        <?php wp_list_cats(‘sort_column=name&optioncount=0&hide_empty=0&all=1’); ?>
    • <?php /* If this is the frontpage */ if ( is_home() || is_page() ) { ?>
      <?php get_links_list(); ?>

      <?php } ?>

    <?php endif; ?>
    </div>

    My functions.php is as follows too:

    <?php
    if ( function_exists(‘register_sidebar’) )
    register_sidebar();
    ?>

    I’ve searched all the themes code for mentions of widgets but haven’t been able to find anything and don’t even know where to start playing around with them so any help would be appreciated!

    Indeed… what the code in your sidebar.php file does is: If the widgets feature is available and there are widgets, then show these widgets, if not, then show the regular sidebar.

    If you want your regular sidebar AND the widgets then you might want to change your code to something like:

    <div id="sidebar">
    
    <?php if ( !function_exists('dynamic_sidebar') || !dynamic_sidebar() ) : ?>
        <!-- What happens if there are no widgets -->
    <?php endif; ?>
    
    <?php wp_list_pages('title_li=<h2>Pages</h2>' ); ?>
    
    <h2>Archives</h2>
    <?php wp_get_archives('type=monthly'); ?>
    
    <h2>Calendar</h2>
    <?php get_calendar(1); ?>
    
    <h2>Categories</h2>
    <?php wp_list_cats('sort_column=name&optioncount=0&hide_empty=0&all=1'); ?>
    
    <?php /* If this is the frontpage */ if ( is_home() || is_page() ) { ?>
    <?php get_links_list(); ?>
    
    <?php } ?>
    
    </div>

    Aahh, thank you very much. I didn’t realise it worked like that, maybe i’ll try to just use widgets so.

    Thanks again,
    S.h.2001

Viewing 10 replies - 1 through 10 (of 10 total)
  • The topic ‘Widget problem’ is closed to new replies.