我知道这是一个真正的新手问题,但我似乎无法从帖子中获得循环。它所做的只是从页面本身中提取。
我制作了一个模板并添加了循环。
<?php
if( have_posts() ) {
while( have_posts() ) {
the_post();
?>
<h2><?php the_title(); ?></h2>
<?php
}
}
?>
编辑:以下是所有代码:http://pastebin.com/k2rDu53b我知道这是一个真正的新手问题,但我似乎无法从帖子中获得循环。它所做的只是从页面本身中提取。
我制作了一个模板并添加了循环。
<?php
if( have_posts() ) {
while( have_posts() ) {
the_post();
?>
<h2><?php the_title(); ?></h2>
<?php
}
}
?>
编辑:以下是所有代码:http://pastebin.com/k2rDu53b因为您在一个页面上,所以只会显示该页面的查询。因此,您必须创建一个新的查询来引入所需的帖子。用以下内容替换循环:
<?php
$args = array(
\'post_type\' => \'post\'
);
$post_query = new WP_Query($args);
if($post_query->have_posts() ) {
while($post_query->have_posts() ) {
$post_query->the_post();
?>
<h2><?php the_title(); ?></h2>
<?php
}
}
?>
以下是有关查询的更多信息:http://codex.wordpress.org/Class_Reference/WP_Query有一种方法可以使用$query->set(\'tax_query\', ...) 在里面pre_get_posts 滤器例如,下一个代码不会更改查询。请注意,我正在从和自定义搜索构建$分类法。function custom_search_filter($query) { ... // array(\'taxonomy\' => \'category\', \'field\' => \'id\', \'terms\' => a