[QUICK Q.] Wordpress Widgets on the page?

Discussion in 'WordPress' started by M3rC, Jun 21, 2008.

  1. #1
    Hey!
    just a quick question here - I'm using WordPress 2.5.1 and was wondering if anyone here knows how to embed the widgets on the page and NOT the sidebar.

    I have two widgets I want on the actuall page itself and not the side bar - csFormII and AdSenseManager Ads - I can only add them onto the sidebar not on the middle/center of the page

    thanks :)
     
    M3rC, Jun 21, 2008 IP
  2. arwen54

    arwen54 Active Member

    Messages:
    632
    Likes Received:
    23
    Best Answers:
    0
    Trophy Points:
    60
    #2
    you can put widgets anywhere on a theme but it requires a few changes made to the functions.php file, where the existing widget code is on the sidebar.php file and where the new widget will be on the index.php file. If there is a second sidebar file it needs to be changed too.
    so for example if you had one sidebar and wanted to add another widget on the index page somewhere you would have to have something like this code on your functions.php file:
    
    <?php
    if ( function_exists('register_sidebar') )
        register_sidebars([B]2[/B],array(
            'before_widget' => '<div id="%1$s" class="widget %2$s">',
             'after_widget' => '</div>',
            'before_title' => '<h2>',
            'after_title' => '</h2>',
        ));
    ?>
    Code (markup):
    and then on your sidebar.php you would need to overwrite the existing call to the dynamic sidebar with something like this:
    <div class="sidebar"><ul><?php if ( !function_exists('dynamic_sidebar')
            || !dynamic_sidebar([B]1[/B]) ) : ?>
    <?php endif; ?>
    </ul>
    </div>
    
    Code (markup):
    then wherever you wanted the other widget you would have to hard code something like this:
    <?php if ( !function_exists('dynamic_sidebar')
            || !dynamic_sidebar([B]2[/B]) ) : ?>
    <?php endif; ?>
    
    Code (markup):
    then you will see 2 sidebars in your widgets area in your WordPress and you can drag and drop any of the widgets to any of the "sidebars" even though one is not technically a sidebar. I hope I have not made this too confusing for you. Good luck!
     
    arwen54, Jun 21, 2008 IP
    DomainDomain and e10 like this.
  3. M3rC

    M3rC Peon

    Messages:
    1,493
    Likes Received:
    48
    Best Answers:
    0
    Trophy Points:
    0
    #3
    cool - thanks finally got around the time to work with it and it was pretty simple. I didn't do it but one of the hosting service's admin done it for me :)
     
    M3rC, Jun 23, 2008 IP
  4. BANAGO

    BANAGO Active Member

    Messages:
    456
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    58
    #4
    Very good explanation. Good Job arwen54!
     
    BANAGO, Jun 23, 2008 IP