我如何编写wordpress函数“is_front_page()"?在树枝木材代码? [英] How do I write the wordpress function "is_front_page()" in twig Timber code?

查看:25
本文介绍了我如何编写wordpress函数“is_front_page()"?在树枝木材代码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的目标是使用 Twig 代码仅在我的 wordpress 的索引页面上输出一些内容.我设置了一个名为 Home 的静态页面.

My goal is to simply output something only on the index page of my wordpress using Twig code. I have set a static page called Home.

我已经在我的 base.twig 中尝试过这个:

I have tried this in my base.twig:

{% if is_front_page %}
 Homepage content
{% endif %}

但这并没有做任何事情,我只是发现由于某种原因无法轻易找到它.

But this doesn't do anything and I just find can't easily find it for some reason.

感谢任何帮助!提前致谢

Any help is appreciated! Thanks in advance

推荐答案

Timber 带有 fn(也有 function 的别名),让您可以执行外部 PHP 函数.所以这样的事情会起作用:

Timber comes with the fn (also has alias of function) that let's you execute external PHP functions. So something like this would work:

{% if fn('is_front_page') %}
  Homepage content
{% endif %}

这篇关于我如何编写wordpress函数“is_front_page()"?在树枝木材代码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆