2013-12-11 78 views
1

我试图从我的网站上的模板页面中删除post_parent的帖子。我能够让他们从循环与显示:从循环中删除父级帖子

if (have_posts()) : while (have_posts()) : the_post(); 
    if (($post->post_parent)) { 
     continue; 
    } else { 
     //code to display post 
    } 

的问题是,拼版是仍然显示在页面上,因为仍然有查询比每页我的职位更多内容。这导致分页中有许多空白页面。在我环路模板无济于事

$where .= ' AND post_parent = 0'; 

的query_posts()之前命令:

我试过的变化:

function exclude_children($query) { 
      $query->set('post_parent', 0); 
    } 
    add_action('pre_get_posts', 'exclude_children'); 

和。

回答

0

尝试this

$query = new WP_Query('post_parent=0'); //Display only top-level pages, exclude all child pages: 
+0

所以我使用的是已在使用查询(从一个特定类别抢占了所有的自定义后“产品”)的模板页面。我尝试使用array_merge,但它似乎没有做任何事情: '''array_merge($ wp_query-> query,array('post_parent'=> 0));''' –

+0

@ OrthoClassic-Chris,你不应该合并这些数组,这对你并不好(以你现在这样做的方式进行处理)。你应该在你现有的查询参数中插入'post_parent = 0'。 – s976