0

我查找了默认的 wordpress 3.5.1 小部件类并复制了搜索小部件进行自定义,但我无法在管理页面上显示我的自定义小部件。无法弄清楚出了什么问题,因为一切都类似于默认的。

custom_plugin_search_form/custom_plugin_search_form.php

<?
/*
Plugin Name: custom_plugin_search_form
Plugin URI: http://google.com
Description: bla bla, and bla bla. Indeed bla bla, after bla bla...
Version: 1.0
Author: Albert Ainstaine
Author URI: http://blabla.bla/blabla/bla-widget
*/

class custom_plugin_search_form extends WP_Widget {

    function __construct() {
        $widget_ops = array('classname' => 'widget_search', 'description' => __( "A search form for your site") );
        parent::__construct('search', __('Search'), $widget_ops);
    }

    function widget( $args, $instance ) {
        extract($args);
        $title = apply_filters( 'widget_title', empty( $instance['title'] ) ? '' : $instance['title'], $instance, $this->id_base );

        echo $before_widget;
        if ( $title )
            echo $before_title . $title . $after_title;

        // Use current theme search form if it exists
        get_search_form();

        echo $after_widget;
    }

    function form( $instance ) {
        $instance = wp_parse_args( (array) $instance, array( 'title' => '') );
        $title = $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 esc_attr($title); ?>" /></label></p>
<?php
    }

    function update( $new_instance, $old_instance ) {
        $instance = $old_instance;
        $new_instance = wp_parse_args((array) $new_instance, array( 'title' => ''));
        $instance['title'] = strip_tags($new_instance['title']);
        return $instance;
    }

}

function custom_plugin_search_form_init() {
    if ( !is_blog_installed() )
        return;

    register_widget('custom_plugin_search_form_init');

    do_action('custom_plugin_search_form_init');
}

add_action('init', 'custom_plugin_search_form_init', 1);
4

1 回答 1

0

我确实注意到您对此 php 文件的开始处理指令缺少页面顶部的“php”。目前,您只有<?. 应该是<?php。这可能是一个问题。

于 2013-02-25T17:25:35.150 回答