テーマ プラグイン ディレクトリにカスタム ウィジェットを作成しましたが、期待どおりに動作しているように見えますが、2 つ目のカスタム ウィジェットを登録すると、最初のウィジェットが上書きされてアクセスできなくなります。以下は、ウィジェットの私のコードです。
add_action( 'widgets_init', create_function( '', 'register_widget( "staffWidget" );' ) );
class staffWidget extends WP_Widget{
function staffWidget() {
parent::WP_Widget(true, 'Staff');
}
function widget($args, $instance){
echo "test widget";
}
function update($new_instance, $old_instance){
return $new_instance;
}
function form($instance){
$instance = wp_parse_args( (array) $instance, array( 'title' => '' ) );
if($instance['title']){
$title = $instance['title'];
}
else{
$title = "Add title here";
}
?>
<p><label for="<?php echo $this->get_field_id('title'); ?>">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 attribute_escape($title); ?>" /></label></p>
<?php
}
}
どちらのウィジェットもこの種のコード構造を持っていますが、クラス名が異なり、両方のウィジェットが WP ダッシュボードのプラグイン セクションでアクティブ化されています。どんな助けや提案も大歓迎です。前もって感謝します :)