CMS的循环指导
1 个回答
- 投票数
-
- 2014-06-25
严格来说,您无需在页面模板中使用循环,但这不会造成伤害,页面内容仍将加载,循环仅运行一次,因为只有一个帖子/页面.许多主题在页面模板中都包含一个循环,我想这是一些兼容性问题.
如果您是从头开始构建页面模板,则不需要在其中添加循环,没错,wordpress将从URL中获得正确的内容,但是您仍然需要运行the_post()函数在使用模板标签如the_title(),the_content()等之前.只需将the_post()放在模板顶部即可.
希望这对您有意义,请随时询问您是否需要进一步的说明.
Strictly, you don't need to use a loop in a page template, but it doesn't hurt, the content of the page will still load, the loop will simply only run once as there is only one post/page. Many themes include a loop in page templates, I guess for some compability issue.
If you are building your page template from scratch, you don't need to add a loop to it, you are right, wordpress will get the right content from the URL, but you still need to run the function the_post() before to use template tags like the_title(), the_content(), etc. Just put the the_post() towards the top of the template.
Hope it makes sense to you, don't hesitate to ask if you need further clarifications.
-
同意循环不会造成任何影响,并且无论如何仅在页面上运行一次.Agreed. The loop doesn't hurt and only runs one time on a page anyway.
- 0
- 2014-06-25
- helgatheviking
-
虽然您可能经常没有副作用,但是您可以通过不调用`have_posts()`来破坏事物.当到达循环末尾时,对have_posts()的最后一次调用将触发loop_end操作.如果您不使用完整循环代码,则与该操作相关的任何操作都将无法运行.while you may often experience no side-effects, you can potentially break things by not calling `have_posts()`. when the end of the loop is reached, the last call to `have_posts()` triggers the `loop_end` action. anything hooked to that action won't run if you don't use the full loop code.
- 0
- 2014-06-25
- Milo
-
感谢您的反馈!我想我还是有些困惑.WP如何将www.example.com/learn/页面与数据库中存储的页面内容SELECT * FROM wp_post关联,而post_id=???? 它是如何知道的,或者如何告诉它检索创建HTML的/learn/页面?Thanks for the feedback! I guess I'm still a little confused though. How does WP associate the page, www.example.com/learn/, with the page content stored in the database, SELECT * FROM wp_post WHERE post_id = ??? How does it know, or how do I tell it to retreive the /learn/ page where I've created the HTML?
- 0
- 2014-06-25
- markmilly
-
它适用于重写URL,这是您在永久链接设置上设置的.浏览器显示的内容/learn/在内部转换为index.php?page=12等.所有这些都是从您抽象出来的,您无需执行任何操作即可使其工作.It works with rewrite URLs, that's what you set up on the permalinks settings. What the browser shows, /learn/, gets translated internally to index.php?page=12, etc. All this is abstracted from you, you don't need to do anything to make it work.
- 0
- 2014-06-25
- Gioia Fueter
也许我会以错误的方式进行操作,但这是我的情况...我想将WordPress用作CMS,而不是博客平台.我有一个网站,该网站将在25至50页之间,并且不会发布任何帖子.
我希望开发自己的主题,这应该很容易,但是我对使用Loop函数感到有些困惑.
我了解:
用于要提取x个帖子的页面,但是在我的场景中,我只想提取页面的内容而不是x个帖子.我需要创建自定义SQL查询吗?
我一直遇到的所有示例都使用The Loop进行发布.如果我只是使用静态页面,是否还需要使用The Loop?我可以使用唯一的URL从MySQL数据库的post列中拉出页面吗?
我希望这是有道理的.