How do I exclude sub-pages from a page loop?

This is what I have so far. Unfortunately this grabs ALL my pages’ titles and content including sub-pages. I only want to display top-level main pages. How can I do this?

<?php query_posts('post_type=page'); ?>
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
         <?php the_title(); ?>
         <?php the_content(); ?>
<?php endwhile; endif; ?>

*Note: I want to display both title and content for the pages. Not just title. Otherwise I would use:

Read More
<?php wp_list_pages('depth=1'); ?>

UPDATE: Following konsolenfreddy’s advice I was able to loop through my pages properly. However a new problem arose. The content is being striped of its tags. Anyway I can keep them? Here’s my new code:

<?php 
  $pages = get_pages('parent=0'); 
  foreach ($pages as $pagg) {
    $option .= $pagg->post_title;
    $option .= $pagg->post_content;
  echo $option;
  }
?>

Related posts

Leave a Reply

2 comments

  1. Does this work?

    <?php query_posts('post_type=page&post_parent='.$parent);?>
    <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
             <?php the_title(); ?>
             <?php the_content(); ?>
    <?php endwhile; endif; ?>