duanqin9631 2017-10-05 20:08
浏览 81
已采纳

Timber(Twig)如何调用wordpress函数

In Timber is this function

{{post}}

where you get things like

{{post.post_title}}

but there are other functions in WordPress like

get_the_permalink();

which are not accessible from post.get_the_permalink or post.get_permalink

these are the variables i can access

  • 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
  • filter

As this Timber documentation describes there are actions [Timber Doc] but you would have to define each function in the functions.php file ... which means i would have to create each already existing function from php and "redirect" it to the wordpress function. Then bind it to Twig.

Also there was a way as you can see here which is now deprecated

  • 写回答

2条回答 默认 最新

  • doutidi5037 2017-10-05 20:36
    关注

    First of all, I believe you should use {{post.link}} to get the Permalink.

    Second, if you find you often need to call php functions from your twig templates, you might not separate between code and template enough. However, since they allow you to call Wordpress-Actions from the template, you could always write a single action in your functions.php that will, depending on the parameters, call the php-function you want. That would be very similar to the fn() call that was suggested.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题