添加对 post 缩略图的主题支持在主题 class 中不起作用

Add theme support for post thumbnail isn't working from theme class

我有一个主题 class,我 bootstrap 我的主题并添加了主题支持,但特色图片元框没有出现。

在 class 文件中:

class WCS_THEME {

    private function __construct() {
        $this->setup_hooks();
    }

    // Singleton design code here

    protected function setup_hooks() {
        add_action( 'after_theme_setup', [ $this, 'setup_theme' ] );
    }

    public function setup_theme() {
        add_theme_support( 'post-thumbnails' );
    }
}
\WCS_THEME\Inc\WCS_THEME::get_instance();

里面 functions.php:

require WCS_DIR_PATH . '/inc/classes/class-wcs-theme.php';

首先,简单地替换

\WCS_THEME\Inc\WCS_THEME::get_instance();

$instance=new \WCS_THEME\Inc\WCS_THEME();

此外, 上面的代码没有出现致命错误有点奇怪。 将调试设置为 TRUE 以查看 PHP 警告。

我认为 WCS_DIR_PATH 存在一些问题。 使用

打印完整路径
echo WCS_DIR_PATH . '/inc/classes/class-wcs-theme.php';

确保它是您文件的正确路径。