Products
GG网络技术分享 2025-03-18 16:12 6
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
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
图片转代码服务由CSDN问答提供
感谢您的意见,我们尽快改进~
功能建议在Timber中是这个函数</ p>
{{post}} </ code> </ pre>
您可以获得</ p>
{{post.post_title}} </ code> < / pre>
但WordPress中还有其他函数,如</ p>
get_the_permalink(); </ code> </ pre>
无法从post.get_the_permalink或post.get_permalink </ p>
访问这些是我可以访问的变量</ p>
- ID </ LI>
- post_author </ LI>
- POST_DATE </ LI>
- post_date_gmt </ LI>
- POST_CONTENT </ LI>
- POST_TITLE </ LI>
- post_excerpt </ LI>
- post_status </ LI>
- comment_status </ LI>
- ping_status </ LI>
- post_password </ LI>
- POST_NAME </ LI>
- to_ping </ LI>
- 执行ping操作</ LI>
- post_modified </ LI>
- post_modified_gmt </ LI>
- post_content_filtered </ LI>
- post_parent </ LI>
- GUID </ LI>
- menu_order </ LI>
- post_type </ li>
- post_mime_type </ li>
- comment_count </ li>
- 过滤器</ li>
</ ul>
正如此Timbe r文档描述了 [Timber Doc] 的行为,但 你必须在functions.php文件中定义每个函数...这意味着我必须从php创建每个已经存在的函数并将其“重定向”到wordpress函数。 然后将它绑定到Twig。</ p>
</ div>
网友观点:
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. ###
You can call any function by using for example
{{ function(\'get_permalink\', post.ID) }}
more infos:
https://timber.github.io/docs/guides/functions/
Demand feedback