如何在 WordPress 3.0 主题中显示内容数据库中的随机帖子?
我正在 http://www.knowledgenation.us 开发一个网页,目前该页面上有大约 500 个帖子。我相信帖子太多了,无法指望有人读完,但我确实相信我的页面具有返回价值。我希望人们定期返回该网页,并始终从该网站获得新的东西。
话虽这么说,我想将我的数据库中的三个随机帖子发布到我的主题网页的正文中。我还想知道如何使该代码模块化,以便我可以将其重用于该网站的新版本,该网站将从我的朋友正在开发的两个网站的 RSS 提要中提取内容。
总而言之,最重要的是,如何将随机帖子发布到网站上,代码是什么样的,请善意解释,因为我对 PHP 编程很陌生,并且不理解代码的大部分内容。我最近刚刚获得了一个 http://www.lynda.com 帐户,我将学习有关 PHP 的所有知识,但是目前我了解甚少。
我预先感谢您在这方面对我的帮助。
I am developing a webpage at http://www.knowledgenation.us and currently I have roughly 500 posts on the page. I believe that is far too many posts to expect someone to read through but I do believe that my page has return value. I want people to return to the webpage on a regular basis and always get something new from the site.
That being said, I would like to post three random posts from my database to the body of the web page that is the theme that I have. I would also like to know how to make that code modular so that I can reuse it for a new incarnation of this website that is going to pull in content from RSS feeds from two websites that friends of mine are developing.
That all being said, bottom line, how do you post random posts to a website, what would the code look like and please be kind in explaining because I am quite new to PHP programming and would not understand most of what the code is about. I just recently got a http://www.lynda.com account and am going to be learning all about PHP but for right now I understand little.
I thank you in advance for helping me with this.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
当您查询帖子时,您可以传递查询属性,例如类别、包含/排除的帖子 ID、限制和偏移量等。您还可以定义结果的排序方式 - 按哪个字段和哪个方向排序(上升/下降)。
order_by
参数可以是常规字段名称,例如title
或date
,也可以是rand
如random
中那样获取随机帖子。这是一个在循环外部使用的 示例,用于获取五个随机帖子:
还有一个示例常规循环:
希望你能看到照片……
When you query your posts, you can pass on query attributes such as a category, included/excluded post ids, limits and offsets, etc.. You can also define how your results will be ordered — by which field and into which direction (ASC/DESC).
The
order_by
parameter can be a regular field names liketitle
ordate
, and alsorand
as inrandom
to fetch random posts.Here's an example to use outside the loop, fetching five random posts:
And another example for a regular loop:
Hope you get the picture…