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()"?在树枝木材代码?


基础教程推荐
- 如何在数学上评估像“2-1"这样的字符串?产生“1"? 2022-01-01
- 将变量从树枝传递给 js 2022-01-01
- Yii2 - 在运行时设置邮件传输参数 2022-01-01
- PHPUnit 的 Selenium 2 文档到底在哪里? 2022-01-01
- php 7.4 在写入变量中的 Twig 问题 2022-01-01
- Web 服务器如何处理请求? 2021-01-01
- php中的foreach复选框POST 2021-01-01
- 使用 scandir() 在目录中查找文件夹 (PHP) 2022-01-01
- 主题化 Drupal 7 的 Ubercart “/cart"页 2021-01-01
- php中的PDF导出 2022-01-01