WordPress get-posts 没有内容(以减少开销)

发布于 2024-10-02 01:57:58 字数 485 浏览 10 评论 0原文

场景:我正在侧边栏中创建可折叠面板,并将所有类别显示为 DIV,并在这些类别 DIV 中显示所有帖子链接。够简单的。我通过 get_categories('orderby=name&order=ASC') 获取了所有类别,现在循环遍历每个类别以获取每个类别中的所有帖子。

问题:代码get_posts('nopaging=1&category='.$category->cat_ID)为我提供了所有帖子,但带有内容还有其他的事情。我想要的只是该帖子的永久链接。就是这样。我相信使用 get_posts 会产生很大的开销,因为 20 多个类别中约有 1000 篇帖子。

解决方案:一个函数或一段代码,可以让我获得一个类别中带有永久链接的所有帖子,而无需其他内容,尤其是内容,因为它是最大的开销。

Scenario: I am creating collapsible panels in the sidebar and displaying ALL categories as DIVs and all Posts links in those category DIVs. Simple enough. I got all categories by get_categories('orderby=name&order=ASC') and now looping through every category to get ALL posts in each category.

Problem: The code get_posts('nopaging=1&category='.$category->cat_ID) gives me all posts but WITH content and other things too. All, I want is the permalink of the post. That's it. I believe using get_posts will thus create big overhead as there are around 1000 posts in over 20 categories.

Solution: A function or piece of code that can just get me all the posts in a category with permalink and without other stuff, especially content as it's the largest overhead.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

三岁铭 2024-10-09 01:57:58

考虑使用自定义查询来准确提取您想要的内容:http://codex.wordpress.org/Displaying_Posts_Using_a_Custom_Select_Query

完成自定义调用后,您可能还想使用 wp_reset_query(),因为当事情开始相互覆盖时,选择查询可能是 WordPress 中的一个有趣的陷阱:http://codex.wordpress.org/Function_Reference/wp_reset_query

在评论后编辑:您需要在 wp_term_relationships 和 wp_posts 之间使用联接,甚至可能与 wp_term_taxonomy 的 3 路连接起到了很好的作用。

说实话,我什至都不会费心——这需要大量的工作,但没有多少好处。 1000 条记录实际上并不算多,Wordpress 已经使用 wp_posts 上的索引来优化其查询。通过使用 wp super 缓存插件为访问者生成静态 HTML 文件,您可能会获得更好的结果( http://wordpress.org/extend/plugins/wp-super-cache/ ),而不是通过复制核心 WP 查询并从选择中删除一些列。

Look into using a custom query to extract exactly what you want: http://codex.wordpress.org/Displaying_Posts_Using_a_Custom_Select_Query

You may want to also use wp_reset_query() after you've finished with your custom call because selecting a query can be a fun Gotcha in wordpress when things start overriding each other: http://codex.wordpress.org/Function_Reference/wp_reset_query

Edited after your comment: You'd need to be using a join between wp_term_relationships and wp_posts, possibly even a 3-way join with wp_term_taxonomy thrown in for good measure.

To be absolutely honest, I wouldn't even bother - it's a lot of work for not a lot of benefit. 1000 records isn't really that much, and Wordpress already uses indexes on wp_posts to optimise its' queries. You'd probably get much better results through using the wp super cache plugin to generate static HTML files for visitors ( http://wordpress.org/extend/plugins/wp-super-cache/ ) than by duplicating core WP queries with a handful of columns removed from the select.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文