Php 在WordPress页面上运行自定义函数
我的WordPress主题Php 在WordPress页面上运行自定义函数,php,arrays,wordpress,custom-fields,Php,Arrays,Wordpress,Custom Fields,我的WordPress主题functions.php文件中有一个函数,包含以下代码: function locations() { $locations_list = array(); query_posts(array('orderby' => 'date', 'order' => 'DESC' , 'post_type' => 'location')); while(have_posts()) { $locations_list[the_
functions.php
文件中有一个函数,包含以下代码:
function locations() {
$locations_list = array();
query_posts(array('orderby' => 'date', 'order' => 'DESC' , 'post_type' => 'location'));
while(have_posts()) {
$locations_list[the_slug()] = the_title();
}
wp_reset_query();
return $locations_list;
}
我的想法是,我可以在我的网站上的任何地方运行这个功能,它将把我所有的帖子存储在一个数组中
然而,我不知道我是如何在公共端运行它的:'(
完美世界,我想在我的footer.php
脚本中运行它
任何帮助都将不胜感激
完美世界,我想在footer.php脚本中运行它
然后从主题中运行footer.php模板中的函数
另外,避免对自定义查询使用query\u posts()
,因为该函数会更改主查询。请直接使用该类:
$query = new WP_Query(array(...));
while($query->have_posts()) {
$query->the_post();
// $locations...
}
仅供参考,在屏幕上打印文章标题,因此您无需将其分配给变量,因为它不返回任何内容。我将尝试一下。马上:-)