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 乌班图ip地址配置及远程SSH
  • ¥15 怎么让点阵屏显示静态爱心,用keiluVision5写出让点阵屏显示静态爱心的代码,越快越好
  • ¥15 PSPICE制作一个加法器
  • ¥15 javaweb项目无法正常跳转
  • ¥15 VMBox虚拟机无法访问
  • ¥15 skd显示找不到头文件
  • ¥15 机器视觉中图片中长度与真实长度的关系
  • ¥15 fastreport table 怎么只让每页的最下面和最顶部有横线
  • ¥15 java 的protected权限 ,问题在注释里
  • ¥15 这个是哪里有问题啊?