How do I write the wordpress function quot;is_front_page()quot; in twig Timber code?(如何编写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
推荐答案
木材 带有 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()"?在树枝木材代码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何编写wordpress函数“is_front_page()"?在树枝木材代码?


- PHP Count 布尔数组中真值的数量 2021-01-01
- Oracle 即时客户端 DYLD_LIBRARY_PATH 错误 2022-01-01
- SoapClient 设置自定义 HTTP Header 2021-01-01
- 如何定位 php.ini 文件 (xampp) 2022-01-01
- Mod使用GET变量将子域重写为PHP 2021-01-01
- 带有通配符的 Laravel 验证器 2021-01-01
- 正确分离 PHP 中的逻辑/样式 2021-01-01
- Laravel 仓库 2022-01-01
- 从 PHP 中的输入表单获取日期 2022-01-01
- 没有作曲家的 PSR4 自动加载 2022-01-01