Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

i have a page template as start page(home.php). i use a 2 columns grid to display all pages on that home.php with title and excerpt. unfortunately also my child pages are shown and i can't figure out how to hide them.

I am not trying to make a list menue or something, its more like a gallery of my pages.

for now i use "query_posts('post_type=page' .$parent);" with the mentioned result. i tried to use an array as well, but this will give me posts instead of pages (fr reasons i havnt understood yet). What am i missing to hide all child pages and only display the parent pages? Any help? Thanks in advance! Dan

share|improve this question

1 Answer 1

There is a parameter in WP_Query called post_parent. Normally this refers to the ID of the post's parent, but since its an integer field, pages without a parent have in essence a post_parent of 0.

So, to get all pages that are not child pages of another page, you could use

query_posts( 'post_type=page&post_parent=0' );

or, in array syntax that would be

query_posts( array( 
    'post_type' => 'page',
    'post_parent' => 0 ) );
share|improve this answer
    
o.k. now i am speechless since i was sure i had tried this and it didn't worked, but i obviously must have done something wrong. your solution works like a charme. Thanks a thousand times!!! the only issue i have now is that the pages are displayed correct, but the order is not the way i used in the main navigation (same pages). i tried to order by count but didnt get this work.. any idea? thans again! –  Dan Dec 29 '11 at 22:41
    
Try 'orderby' => 'menu_order', 'order' => 'ASC' - that will order the pages by the menu order set in the Page Attributes box. If you're talking about the order you've given them is a custom nav menu, though, there's no easy way to get at that order without a lot of joins and filters... –  goldenapples Dec 30 '11 at 0:30

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.