admin管理员组

文章数量:1290388

What I have understood about what's happening when a web page in a Wordpress built web site is loaded is that Wordpress determines which post (page) and which template for that page to load. It then loads the page and the template.

I am actually trying to figure how WP creates a final web page that's being sent to my browser when I click a link in a WP based web site. I am also trying to figure which role the page template plays, particularly when it's basically empty like the one from WP's default twentytwenyone theme. I am asking this because usually I don't edit a page template, I edit a page, put blocks and widgets on it (the latter probably often containing php code). That page is the only thing I care about when building some "regular" web page.

Wordpress somehow throws my page and the related page template together and from that creates the final page that gets sent to my browser.

I am wondering whether the template's post loop is irrelevant in my scenario where everything I want happens by means of what blocks/elements I have put on my web page (which for WP is just a post, I know, but looking at the context, in the end defines a "web page").

What I have understood about what's happening when a web page in a Wordpress built web site is loaded is that Wordpress determines which post (page) and which template for that page to load. It then loads the page and the template.

I am actually trying to figure how WP creates a final web page that's being sent to my browser when I click a link in a WP based web site. I am also trying to figure which role the page template plays, particularly when it's basically empty like the one from WP's default twentytwenyone theme. I am asking this because usually I don't edit a page template, I edit a page, put blocks and widgets on it (the latter probably often containing php code). That page is the only thing I care about when building some "regular" web page.

Wordpress somehow throws my page and the related page template together and from that creates the final page that gets sent to my browser.

I am wondering whether the template's post loop is irrelevant in my scenario where everything I want happens by means of what blocks/elements I have put on my web page (which for WP is just a post, I know, but looking at the context, in the end defines a "web page").

Share Improve this question edited Jun 17, 2021 at 15:17 Razzupaltuff asked Jun 17, 2021 at 13:43 RazzupaltuffRazzupaltuff 1396 bronze badges 5
  • What do you mean by "embedded in my web page"? Do you mean PHP code that you try to paste into the Editor, or code within theme or plugin files? – WebElaine Commented Jun 17, 2021 at 14:30
  • I may e.g. put widgets on my page that contain some php code. – Razzupaltuff Commented Jun 17, 2021 at 15:05
  • If you mean a WordPress Widget, in a sidebar, then yes, your PHP will be executed. If instead you mean you're trying to place PHP directly into the Editor, no, it will not be executed, because WP is trying to prevent security issues that can happen when PHP goes directly into the content and is run. You may need to look into a Block (if you're using Block Editor) or a Shortcode (if you're using Classic Editor), or you may need to look farther into the theme hierarchy and how all your template files work, depending on where you want to run your code. – WebElaine Commented Jun 17, 2021 at 18:25
  • I have widgets on some of my web pages that query posts, display them in a 4x2 grid, and allow to extend that grid on button click with more posts. Where is the difference between that and a widget in a sidebar? In the end, a sidebar is just an arbitrary part of the entire page. – Razzupaltuff Commented Jun 17, 2021 at 18:34
  • Just trying to clarify "a WordPress widget" from "a component somewhere on a page." If it's a WP widget it acts the same way no matter where in the site it lives. – WebElaine Commented Jun 18, 2021 at 15:18
Add a comment  | 

1 Answer 1

Reset to default 0

What happens next?

Nothing. That's it. Loading the template is the last thing that happens.

I suppose the post loop in the template gets executed.

When the template is loaded the PHP code in it just gets run like any other PHP code.

Most templates should include a pattern of code that's called 'the loop'. This code does what the documentation says it does.

Where and how does any php code embedded in my web page come into play here?

You don't embed PHP code in page content in WordPress.

本文标签: postsWhen and how will php code in a user made Wordpress page be executed