2013-12-11 76 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