Wordpress 如何为博客文章生成 HTML [英] How Wordpress Generates HTML for Blog Posts

查看:51
本文介绍了Wordpress 如何为博客文章生成 HTML的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图弄清楚 Wordpress 是如何围绕博客文章工作的,以便我可以在我的 Web 应用程序中实现类似的功能.这可能是一些基本的 php,但我似乎不知道如何做到这一点!

I am trying to figure out how exactly Wordpress works around blog posts so that I can implement something similar in my web application. And this is probably some basic php, but I can not seem to find out exactly how to do this!

通常,您有一个类似于 http://www.example.com/blog/2012/01/27/some-title 的 URL.而且我知道文件 http://www.example.com/blog/2012/01/27/some-title/index.php 不存在.Wordpress 采取的行动路径是什么,以及为了生成博客文章的 html 需要设置的任何 php 设置是什么?是否与缺少/无效 url 路径的 404 错误页面有关?

Typically you have a a URL like http://www.example.com/blog/2012/01/27/some-title. And I know that the file http://www.example.com/blog/2012/01/27/some-title/index.php does not exist. What is the path of action that Wordpress takes and any php settings that need to be set in order for the html for the blog post to be generated? Is it related to a 404 error page for missing / invalid url paths?

推荐答案

Wordpress 所做的——以及许多流行的 MVC 框架——是将所有流量路由到一个 前端控制器wikipedia 使用 apache .htaccess 文件的脚本.然后框架/CMS 将请求的 URL 的组成部分分解,以确定应该执行哪个控制器来返回请求的内容.它如何确定将请求路由到何处的底层细节因框架而异.

What Wordpress does -- and indeed many of the popular MVC frameworks -- is route ALL traffic to a single Front Controllerwikipedia script using an apache .htaccess file. The component parts of the requested URL are then broken apart by the framework/CMS to determine what controller should be executed to return the requested content. The underlying details of how it determines where to route the request vary from framework to framework.

前端控制器通常会处理错误显示,并且它(或确定的控制器)能够决定所请求的资源是否确实存在.

The front controller will generally handle error displays as well as it (or the determined controller) is able to decide if the requested resource actually exists.

因此执行路径将类似于:

So the path of execution will be something like:

  1. 生成请求
  2. 将请求路由到适当的控制器
  3. 执行/调用控制器 - 或者 - 如果请求的资源不存在则显示错误

我相信 Wordpress 实际上吸收了所有流量并将其指向前端控制器.这对于对 PHP 编程或 .htaccess 规则知之甚少的普通 Wordpress 用户来说非常有用.但是,通常建议允许仍然通过 .htaccess 文件中的条件访问引用服务器上实际存在的文件或目录的请求,而不是像所有其他请求一样将它们路由到前端控制器.

I believe Wordpress actually sucks up ALL traffic and points it to the front controller. This is great in the case of the average Wordpress user who knows little about PHP programming or .htaccess rules. However, it's generally advisable to allow requests that reference files or directories that actually exist on the server to still be accessed via conditions in the .htaccess file instead of routing them to the front controller like all other requests.

这篇关于Wordpress 如何为博客文章生成 HTML的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆