开发者

Using widgets outside the sidebar?

Is it possible to use widgets outside of the sidebar? When you assign them in the admin panel you have to drag them to your sidebar开发者_Go百科 but I would like to implement a search function outside the sidebar. Can I do this?


The correct answer is use the_widget()

I used it to integrate a widget into my own custom widget. Check out the codex for details on how to use it.


Absolutely. This thread in the WordPress support forums should get you going. It creates a new widget area ready called Homepage that can then be used in any of your theme's template files:

Your theme's functions.php

if (function_exists('register_sidebar')) {
    register_sidebar(array(
        'name'=> 'Main',
        'id' => 'main',
        'before_widget' => '<div class="widget_box side">',
        'after_widget' => '</div>',
        'before_title' => '<h3>',
        'after_title' => '</h3>',
    ));
    register_sidebar(array(
        'name'=> 'Homepage',
        'id' => 'homepage',
        'before_widget' => '<div class="widget_box">',
        'after_widget' => '</div>',
        'before_title' => '<h3>',
        'after_title' => '</h3>',
    ));
}

The template file you want the Homepage widget in

<?php if (function_exists('dynamic_sidebar') && dynamic_sidebar('Homepage')) : ?>

Alternatively, you can use the My Custom Widgets plugin to do the same thing.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜