dougong7850 2019-02-11 23:24
浏览 55

在运行木材起动器主题时找不到“木材”类

I have recently installed Timber on to my WordPress instance but whenever I try to run single.php for the timber-starter I get the following error:

Fatal error: Uncaught Error: Class 'Timber' not found in www\Website\wp\wp-content\plugins\timber-library\timber-starter-theme\single.php:12 Stack trace: #0 {main} thrown in www\Website\wp\wp-content\plugins\timber-library\timber-starter-theme\single.php on line 12

I have read that there can be issues with namespace and to update it to Timber\Timber. I have tried this also and get the same class not found for Timber\Timber. Interestingly, if I open it in PHPStorm I can navigate to the function directly from the class call so it is able to recognise it there.

Does anyone have any ideas? I've tried different versions of PHP, different versions of WordPress and installing via WP-Admin and manually. None of these options are fixing this issue. (Please note, I also get this error for going to index.php in this directory).

Here is the code from single.php with the added namespace definition.

<?php
/**
 * The Template for displaying all single posts
 *
 * Methods for TimberHelper can be found in the /lib sub-directory
 *
 * @package  WordPress
 * @subpackage  Timber
 * @since    Timber 0.1
 */ 

 use Timber\Timber; 

$context = Timber::get_context();
$post = Timber::query_post();
$context['post'] = $post;

if ( post_password_required( $post->ID ) ) {
    Timber::render( 'single-password.twig', $context );
} else {
    Timber::render( array( 'single-' . $post->ID . '.twig', 'single-' . $post->post_type . '.twig', 'single.twig' ), $context );
}

  • 写回答

1条回答 默认 最新

  • duanlu1908 2019-03-31 09:06
    关注

    It must seems trivial, but this error is commonly caused by a misinstallation. If you use Timber as a plugin, check if it is activated.

    If you have installed trough a package manager, check you have used the right package name composer require timber/timber.

    You can also try to remove your package and re-install it.

    If all is correct, check your functions.php, myabe there is a misuse of the Timber Instance

    评论

报告相同问题?

悬赏问题

  • ¥15 java 操作 elasticsearch 8.1 实现 索引的重建
  • ¥15 数据可视化Python
  • ¥15 要给毕业设计添加扫码登录的功能!!有偿
  • ¥15 kafka 分区副本增加会导致消息丢失或者不可用吗?
  • ¥15 微信公众号自制会员卡没有收款渠道啊
  • ¥15 stable diffusion
  • ¥100 Jenkins自动化部署—悬赏100元
  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘