Php 如何在数据库中存储和检索小部件数据?

Php 如何在数据库中存储和检索小部件数据?,php,wordpress,Php,Wordpress,我正在尝试开发一个插件,它可以帮助上传与之相关的图片标题和描述。之后,在前端显示相同的内容。这是我的密码: <?php /* Plugin Name: Custom News Scroller Plugin URI: http://url.com Description: description. Author: name Version: 1.0 Author URI: http://url.com */ class CustomNewsScrollerWidget extends

我正在尝试开发一个插件,它可以帮助上传与之相关的图片标题和描述。之后,在前端显示相同的内容。这是我的密码:

<?php
/*
Plugin Name: Custom News Scroller
Plugin URI: http://url.com
Description: description.
Author: name
Version: 1.0
Author URI: http://url.com
 */

 class CustomNewsScrollerWidget extends WP_Widget
{
        function CustomNewsScrollerWidget() {
        $widget_options = array(
        'classname'     =>      'custom-news-scroller-widget',
        'description'   =>      'Helps to scroll news'
        );

        parent::WP_Widget('custom_news_scroller_widget', 'Custom News Scroller', $widget_options);
    }


    function widget( $args, $instance ) {
        extract ( $args, EXTR_SKIP );
        $title = ( $instance['title'] ) ? $instance['title'] : 'A simple widget';
        $body = ( $instance['body'] ) ? $instance['body'] : 'A simple message'
        ?>
        <?php echo $before_widget ?>
        <?php echo $before_title . $title . $after_title ?>
        <p><?php echo $body ?></p>
        <?php 
    }

    function update() {

    }

    function form($instance) {
        ?>
        <label for="<?php echo $this->get_field_id('title'); ?>">
            Title:
            <input id="<?php echo $this->get_field_id('title'); ?>" 
            name="<?php echo $this->get_field_name('title'); ?>" 

            value="<?php echo esc_attr($instance['title'])  ?>" />

        </label>

            <label for="<?php echo $this->get_field_id('description'); ?>">
            Description:
            <input id="<?php echo $this->get_field_id('description'); ?>" 
            name="<?php echo $this->get_field_name('description'); ?>" 

            value="<?php echo esc_attr($instance['description'])  ?>" />

        </label>
        <?php

    }

}

function custom_news_scroller_widget_init() {
    register_widget("CustomNewsScrollerWidget");
}
add_action('widgets_init','custom_news_scroller_widget_init');

您的函数更新为空。。小部件使用此功能保存数据


参考这里

什么不适合你?你有什么确切的错误?你查过电话号码了吗?
function update() {

    }