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


基础教程推荐
- 如何在 Laravel 5.3 注册中添加动态下拉列表列? 2021-01-01
- 如何在 Laravel 中使用 React Router? 2022-01-01
- 在PHP中根据W3C规范Unicode 2022-01-01
- Cron Jobs 调用带有变量的 PHP 脚本 2022-01-01
- YouTube API v3 点赞视频,但计数器不增加 2022-01-01
- PHP 类:全局变量作为类中的属性 2021-01-01
- PHP PDO MySQL 查询 LIKE ->多个关键词 2021-01-01
- 学说 dbal querybuilder 作为准备好的语句 2022-01-01
- 如何替换eregi() 2022-01-01
- 有什么方法可以用编码 UTF-8 而不是 Unicode 返回 PHP`json_encode`? 2021-01-01