如何编写wordpress函数“is_front_page()"?在树枝木材代码?

2022-01-22 00:00:00 php wordpress twig

我的目标是使用 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

推荐答案

木材 带有 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 %}

相关文章