最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

theme twenty twenty two - TwentyTwentyTwo - How to add PHP logic to Post templates?

programmeradmin4浏览0评论

I'm testing out the new TwentyTwentyTwo theme for WordPress 5.9. I can see that when I enter a post, on the right side I have the option to either Edit or Create New Templates.

In edit mode, it brings us into the edit view of that template (which kinda reminds me of a reusable block in a way..)

But how do we "edit and save" PHP code for these templates? Like loops, actions, do_actions, etc... I don't see the templates being auto generated in my Visual Studio Code environment anywhere....

I'm testing out the new TwentyTwentyTwo theme for WordPress 5.9. I can see that when I enter a post, on the right side I have the option to either Edit or Create New Templates.

In edit mode, it brings us into the edit view of that template (which kinda reminds me of a reusable block in a way..)

But how do we "edit and save" PHP code for these templates? Like loops, actions, do_actions, etc... I don't see the templates being auto generated in my Visual Studio Code environment anywhere....

Share Improve this question edited Mar 1, 2022 at 14:12 fuxia 107k38 gold badges255 silver badges459 bronze badges asked Feb 28, 2022 at 18:32 klewisklewis 8991 gold badge14 silver badges29 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 0

But how do we "edit and save" PHP code for these templates? Like loops, actions, do_actions, etc... I don't see the templates being auto generated in my Visual Studio Code environment anywhere....

You don't, these are block templates, not PHP templates. When in the filesystem in a theme they are plain .html files, and when you modify or create them in the user interface they're saved in the database.

In order to run PHP code in these templates you would need one of the following:

  • a custom block that renders in PHP
  • a custom shortcode inserted via a shortcode block

This is the same as asking how to run PHP inside a posts content, and the solutions are the same. Custom blocks and shortcodes.

发布评论

评论列表(0)

  1. 暂无评论