2009-11-05 69 views
0

我明白这个函数的WordPress的部件:如何正确修改控件这个WordPress的功能?

register_sidebar(array(
     'name' => 'sidebar', 
     'before_widget' => '<div id="%1$s" class="widget %2$s"><div class="widgetTop"></div>', 
     'after_widget' => '</div>', 
     'before_title' => '<h2 class="accordion_toggle">', 
     'after_title' => '</h2>', 
    )); 

before_titleafter_title是我的小部件的H2标题和before_widgetafter_widget包围部件本身。

但是如果我需要把一类的小工具里面,而不是外面?我希望小部件中的所有内容都具有某个类。将正确的语法是什么这个(inside_widget)?

+0

见http://wordpress.org/support/topic/328671 – Michael 2009-11-06 19:03:17

回答

0

可能是你需要这个 此示例代码创建一个Widget命名FooWidget具有设置形成改变显示标题。

/** 
* FooWidget Class 
*/ 
class FooWidget extends WP_Widget { 
    /** constructor */ 
    function FooWidget() { 
     parent::WP_Widget(false, $name = 'FooWidget'); 
    } 

    /** @see WP_Widget::widget */ 
    function widget($args, $instance) {  
     extract($args); 
     $title = apply_filters('widget_title', $instance['title']); 
     ?> 
       <?php echo $before_widget; ?> 
        <?php if ($title) 
         echo $before_title . $title . $after_title; ?> 
        Hello, World! 
       <?php echo $after_widget; ?> 
     <?php 
    } 

    /** @see WP_Widget::update */ 
    function update($new_instance, $old_instance) {    
     return $new_instance; 
    } 

    /** @see WP_Widget::form */ 
    function form($instance) {    
     $title = esc_attr($instance['title']); 
     ?> 
      <p><label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('Title:'); ?> <input class="widefat" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" type="text" value="<?php echo $title; ?>" /></label></p> 
     <?php 
    } 

} // class FooWidget 
// register FooWidget widget 
add_action('widgets_init', create_function('', 'return register_widget("FooWidget");')); 

可能是你需要这个