2013-01-21 43 views
0

我正在構建我的第一個WordPress的自定義小部件,我對此持懷疑態度。到目前爲止,這是WordPress的小部件開發

<?php 

//Add an action that will load all widgets 
add_action('widgets_init', 'ma_load_widgets'); 

//Function that registers the widgets 
function ma_load_widgets() { 
register_widget('ma_my_widget'); 
} 
/*----------------------------------------------------------------------------------- 

Plugin Info : Goes here 

-----------------------------------------------------------------------------------*/ 

class ma_my_widget extends WP_Widget { 

function ma_my_widget(){ 

    code_goes_here 

} 

function widget($args, $instance){ 

    extract($args); 

    code_goes_here 

} 

function update($new_instance, $old_instance){ 

    $instance = $old_instance; 

    code_goes_here 

    return $instance; 

} 

function form($instance){ 

    code_goes_here 

} 

} 

?> 

我已保存這段代碼爲widget.php文件放入文件夾包括,我的工作在WP 3.5二12,但是當我在去小部件我部件的結構我後端我看不到它。我究竟做錯了什麼?

回答

1

我已保存這段代碼爲widget.php文件,並放置到包括 文件夾

這是不對的。添加「插件頭」在你widget.php文件的頂部,如:

<?php 
/* 
Plugin Name: Ma My Widget :) 
Description: My widget 
Version: 1.0 
Author: Me 
License: GPL2 
*/ 
?> 

把你的插件文件夾中的文件,然後你會看到它在插件頁中列出您的信息中心。激活它,你還可以看到儀表板窗口小部件

檢查了他們的Plugin APIWidget API