根据木材documentation,您可以使用meta
获取ACF字段。
将图像字段返回类型设置为image_id
。然后您可以得到如下图像:
$context['current_user'] = new Timber\User();
Timber::render('single.twig',$context);
<img src="{{ Image(current_user.meta('your_field_name')).src }}" />
要获取帖子作者元字段:
<img src="{{ Image(post.author.meta('your_field_name')).src }}" />
,
我在贾尼尔(Jainil)的帮助下解决了我的问题。我的解决方案如下。
single.php
$context = Timber::context();
$timber_post = Timber::query_post();
$context['post'] = $timber_post;
if ( post_password_required( $timber_post->ID ) ) {
Timber::render( 'single-password.twig',$context );
} else {
Timber::render( array( 'single-' . $timber_post->ID . '.twig','single-' . $timber_post->post_type . '.twig','single-' . $timber_post->slug . '.twig','single.twig' ),$context );
}
此处不需要其他代码。 Jainil建议使用$context['current_user'] = new Timber\User();
,但这不是必需的。
single.twig
<img src="{{ Image(post.author.meta('author_profile_image')).src }}" class="" alt="{{ Image(post.author.meta('author_profile_image')).alt }}" />
我希望这对其他人有帮助。
本文链接:https://www.f2er.com/3105453.html