首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >未显示自定义wordpress小工具的设置

未显示自定义wordpress小工具的设置
EN

Stack Overflow用户
提问于 2019-03-29 06:48:11
回答 1查看 353关注 0票数 0

我正在尝试为一个子主题扩展wordpress (v5.1.1)中的默认图库小部件。小部件显示在仪表板的“小部件”部分,但表单字段从不显示以编辑小部件设置。下面显示了默认图库小部件的行为,然后是我的小部件(称为“扩展图库”)。

我做了什么:我将/wp-includes/widgets/class-wp-widget-media-gallery.php的内容复制并粘贴到我的子主题中的一个名为extended-gallery.php的文件中。这两个文件是完全相同的,除了在extended-gallery.php的开头,我更改了类名和句柄。

see class-wp-widget-media-gallery.php

我在extended-Gallery.php中所做的更改:

代码语言:javascript
复制
class Extended_Gallery extends WP_Widget_Media {

    /**
     * Constructor.
     *
     * @since 4.9.0
     */
    public function __construct() {
        parent::__construct(
            'media_gallery_extended',
            __( 'Extended Gallery' ),
            array(
                'description' => __( 'Displays an image gallery.' ),
                'mime_type'   => 'image',
            )
        );

在functions.php中,我注册了extended-gallery.php

代码语言:javascript
复制
<?php

//custom widgets

require_once("extended-gallery.php");
add_action("widgets_init", "custom_widgets_init");

function custom_widgets_init(){
  register_widget("Extended_Gallery");
}

// add custom style

add_action( 'wp_enqueue_scripts', 'my_theme_enqueue_styles' );
function my_theme_enqueue_styles() {

    $parent_style = 'parent-style'; 

    wp_enqueue_style( $parent_style, get_template_directory_uri() . '/style.css' );
    wp_enqueue_style( 'child-style',
        get_stylesheet_directory_uri() . '/style.css',
        array( $parent_style ),
        wp_get_theme()->get('Version')
    );
}

?>

如何让自定义小部件的设置字段与默认的图库小部件以相同的方式工作?如果我添加额外的字段,它会搞砸吗?

EN

回答 1

Stack Overflow用户

发布于 2019-03-29 08:46:41

你的问题是关于在wordpress上创建一个新的插件。你应该“注册”你的小部件。如下所示。

代码语言:javascript
复制
add_action( 'elementor/widgets/widgets_registered', [ $this, 'init_widgets' ] );  

你应该激活你的新插件。祝好运。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/55407988

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档