我有一个"front-page.php“,它是一个静态的单边页面。如果我使用Wordpress循环在front-page.php上查看我的最新帖子,它们都会出现。现在我想创建一个新闻页面,所以我创建了一个文件" page -news.php“。删除了首页的循环代码,并将其粘贴到页面新闻中。尽管如此,什么也没发生。
循环代码:
<?php get_header();?>
<?php
if (have_posts()):
while (have_posts()): the_post();?>
<?php the_title();?>
<?php the_content();?>
<?php
endwhile;
else: echo '<p>no posts were found</p>';
endif;
?>
<?php get_footer();?>我错过了什么?
发布于 2015-12-27 19:56:59
你需要添加wp_Query,主页被认为是一个博客页面,所以它有默认的查询。
$args = array (
/*'cat' => $catNum,*/
'post_type' => 'post',
'pagination' => false,
'posts_per_page' => '-1',
'ignore_sticky_posts' => false,
'order' => 'DESC',
'orderby' => 'date',
);
// The Query
$query = new WP_Query( $args );您应该在此之前添加此代码
if (have_posts()):
while (have_posts()): the_post();?>关于have_posts()的这一部分将是
// The Loop
if ( $query->have_posts() ) { ?>
<?php while ( $query->have_posts() ) {
$query->the_post();不要忘记在最后添加wp_reset_postdata();,这样你就可以在一个页面中使用多个查询。
https://stackoverflow.com/questions/34307967
复制相似问题