admin管理员组

文章数量:1317898

I am new to WordPress theme development. I'd like to create a new widget based on the built-in Image widget, with additional fields such as 'description' & 'speaker'... etc. The widget is called 'My Poster'. I added the file poster.php and it is like:

class WP_Widget_Media_Poster extends WP_Widget_Media
{
    parent::__construct(
        'media_poster', __('My Poster'),
        array(
            'description' => __('Displays a Poster.'),
            'mime_type'   => 'image',
        )
    );
    :
    :

I already added the required code to function.php as follow:

  • require_once get_template_directory() . '/widgets/poster.php';
  • register_widget('WP_Widget_Media_Poster');

I can see the new widget in the "Available Widgets" page, and I am able to add it to my sidebar. However, the original field "Title" and the "Add Image" button do not show up. Only the 'Delete' and 'Done' links appear at the bottom.

Two questions:

  1. is this the right approach to create this new widget by extending the built-in WP_Widget_Media class? if so,
  2. how to properly do it?

Thank you.

brian

本文标签: widgetsHow to extend WPWidgetMedia