在Timber中就是这个功能
{{post}}
你得到的东西
{{post.post_title}}
但是WordPress中还有其他功能
get_the_permalink();
无法从post.get_the_permalink或post.get_permalink访问
这些是我可以访问的变量
-
ID
-
post_author
-
post_date
-
post_date_gmt
-
post_content
-
post_title
-
post_excerpt
-
post_status
-
comment_status
-
ping_status
-
post_password
-
post_name
-
to_ping
-
pinged
-
post_modified
-
post_modified_gmt
-
post_content_filtered
-
post_parent
-
guid
-
menu_order
-
post_type
-
post_mime_type
-
comment_count
-
过滤器
正如这个Timber文档描述的那样,有一些动作[Timber Doc]但你必须在functions.php文件中定义每个函数...这意味着我必须从php创建每个已经存在的函数,并且"redirect"它到wordpress函数 . 然后将其绑定到Twig .
还有一种方法,你可以看到here现在是deprecated
2 回答
首先,我相信您应该使用
{{post.link}}
获取固定链接 .其次,如果您发现经常需要从twig模板调用php函数,则可能无法在代码和模板之间进行足够的分离 . 但是,因为它们允许您从模板中调用Wordpress-Actions,所以您总是可以在functions.php中编写一个动作,根据参数调用您想要的php函数 . 这与建议的
fn()
呼叫非常相似 .您可以使用例如调用任何函数
更多信息:https://timber.github.io/docs/guides/functions/