WordPress.org

Ready to get started?Download WordPress

Forums

Widget problem (11 posts)

  1. sensifreak
    Member
    Posted 6 years ago #

    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

  2. wp_guy
    Member
    Posted 6 years ago #

    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.

  3. sensifreak
    Member
    Posted 6 years ago #

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

  4. wp_guy
    Member
    Posted 6 years ago #

    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.

  5. sensifreak
    Member
    Posted 6 years ago #

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

  6. wp_guy
    Member
    Posted 6 years ago #

    http://wpguy.com/contact ;-) I don't want to get spammed by everyone :-D

  7. Ivovic
    Member
    Posted 6 years ago #

    *spams the contact form*

  8. wp_guy
    Member
    Posted 6 years ago #

    lol >:-O

  9. Stonedhippy2001
    Member
    Posted 6 years ago #

    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!

  10. wp_guy
    Member
    Posted 6 years ago #

    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>
  11. Stoned Hippy
    Member
    Posted 6 years ago #

    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

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags