2013-08-28 112 views
-2

我想開發一個插件,它有助於上傳圖片標題和相關的描述。之後,在前端顯示相同的內容。這裏是我的代碼:如何存儲和檢索數據庫中的Widget數據?

<?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'); 

我有一個2輸入文本框,輸入標題和說明。如何將這些信息存儲在數據庫中?以及如何從數據庫中檢索相同的內容?

+0

什麼不適合你?你有什麼確切的錯誤?你是否檢查過[Codex中的示例](http://codex.wordpress.org/Widgets_API)? – brasofilo

回答

相關問題