# 基本的なウィジェット

## ウィジェットとは

## 一番簡単なウィジェット

```php
class My_Widget extends WP_Widget {

    public function __construct() {
        parent::__construct(
            'my_widget', // Base ID
            __('My Widget', 'text_domain'), // Name
            array( 'description' => __( 'A my widget', 'text_domain' ), ) // Args
        );
    }

    public function widget( $args, $instance ) {
        echo 'hello world';
    }

    public function form( $instance ) { }

    public function update( $new_instance, $old_instance ) {
        return array();
    }
}

// make WordPress aware of this widget:
add_action( 'widgets_init', function(){
     register_widget( 'My_Widget' );
});
```

* `__construct`
* `widget`
* `form`
* `update`

## ウィジェットフィールドの追加

バックエンドにフォームフィールドを追加し、フロントエンドのそのフィールドにアクセスする

## `the_widget`

サイドバーなしでウィジェットを表示させるには

```php
the_widget( $widget, $instance, $args );
```

これを行う必要があるとのなら、やり方を再考すべきでしょう。


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://www.wptherightway.org/japanese/widgets/a_basic_widget.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
