0

我正在使用https://carbonfields.net/为 wordpress 主题创建自定义选项

我试图将此代码复制到functions.php中:

use Carbon_Fields\Widget;
use Carbon_Fields\Container;





class Banner_Widget extends Widget {
    function __construct() {
        $this->setup( 'banner', __( 'Banner', 'crb' ), __( 'Displays a custom banner.' ), array(
            Field::make( 'attachment', 'image', __( 'Image' ) )
                ->set_required( true ),
            Field::make( 'text', 'link', __( 'Link' ) )
                ->set_required( true ),
        ));
    }

    function front_end( $args, $instance ) {
        echo '<a href="' . esc_url( $instance[ 'link' ] ) . '">';

        echo wp_get_attachment_image( $instance[ 'image' ], 'medium' );

        echo '</a>';
    }
}

add_action( 'widgets_init', 'my_register_custom_widgets' );
function my_register_custom_widgets() {
    register_widget( 'Banner_Widget' );
}

我最终得到了这个:

在此处输入图像描述

我不明白这个错误,因为use Carbon_Fields\Widget;已经找到了。

我在 PHP 7+ 中使用 Xampp

4

0 回答 0