继lynda的课程后,我做了这个,稍微修改了他们的基本例子。它显示在我的Wordpress管理员中,我可以将它拖到我的侧边栏小部件中。它应该做的是将Bee Gees歌词插入我的侧边栏(换句话说,基本的问候词),但边栏中没有这样的歌词,无论我放置小部件的位置。
我的wordpress插件目录中的代码全部在discowidget.php中,正如我所说,它存在于管理员中。这是代码:
<?php
/*
Plugin Name: Disco Widget
Plugin URI: gopher://disco/
Description: This is not just a plugin, it symbolizes the hope and enthusiasm of an entire generation summed up in modernist lyrics sung most famously by the Bee Gees: Disco. When activated you will randomly see a lyric from the disco era.
Author: Disco Stu
Version: Jesus
Author URI: http://tenprinthello.ca/
*/
class DiscoWidget extends WP_Widget
{
function DiscoWidget ()
{
}
function widget($args, $instance)
{
exract( $args, EXTR_SKIP );
$title = ( $instance['title'] ) ? $instance['title'] : 'The Disco Widget';
$body = ( $instance['body'] ) ? $instance['body'] : 'Well, you can tell by the way I use my walk.';
?>
<?php echo $before_widget; ?>
<?php echo $before_title . $title . $after_title ?>
<p><?php echo $body ?></p>
<?php
}
function update()
{
}
function form()
{
}
}
function disco_widget_init()
{
register_widget("DiscoWidget");
}
add_action('widgets_init','disco_widget_init');
?>
答案 0 :(得分:0)
首先,我建议使用构造函数并删除名为DiscoWidget()的函数:
//function DiscoWidget(){}
function __construct() {
parent::__construct('DiscoWidget', 'DiscoWidget', array( 'description' => 'DiscoWidget') );
}
另外,回复你的结束$ after_widget:
<?php echo $after_widget; ?>