Wordpress显示来自查询的结果帖子

问题描述 投票:0回答:2

我在Wordpress中很新,我想调用一个模板来显示我的查询中的结果帖子,我在主题的functions.php中写了这些帖子:

$quotes = get_posts(array('post_type'=>'post', 'orderby'=>'title', 'order'=>'ASC', 'meta_value' =>$criterion)); 

我有结果和模板页面,但我不知道如何将它们发送到特定模板。如何调用模板并发送$ quotes,例如call_template(template_name,$ quotes)

php wordpress
2个回答
0
投票

应该只是将它放在一个函数中,返回$ quotes,确保包含functions.php(如果它还没有),然后调用函数?

除非你打算将它挂钩到另一个wordpress功能。


0
投票

如果你只是想在某个页面上显示它,而不仅仅是在页面上创建页面模板和查询,并放置一个wordpress has_posts()循环,你应该参考模板herirachy https://developer.wordpress.org/themes/basics/template-hierarchy/

并且您将知道给定页面加载的主题目录中的哪个php文件。或者有一个有趣的插件,知道哪个模板文件涉及给定的页面,这个插件https://developer.wordpress.org/themes/basics/template-hierarchy/

© www.soinside.com 2019 - 2024. All rights reserved.