• I would like to run a query and get the excerpt of more than one childpage but only showing the recent page of all those childpages.

    Example: Page- Childpage ID=111 -Grandchild1
    -Grandchild2

    Childpage2 ID=134 -Grandchild3
    -Grandchild4
    -Grandchild5

    I would like to query childpage 1 and 2 but only showing the latest page of the 5 grandchilds.

    At the moment im using

    <?php query_posts('post_type=page&child_of=111&showposts=1&monthnum=$current_month'); ?>
    			<?php while (have_posts()) : the_post(); ?>
    <div class="green1">
    			<h1><?php the_title(); ?></h1>
    			<?php the_excerpt(); ?>
    			<a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>">weiterlesen...</a>
    </div>
    	<?php endwhile; ?>

    which works fine fpr 1 Childpage but i dont know how to make a query for more than one child of.

    Would be cool if i could use a query to display the newest page out of 111 and 134

    Greetings Baal Orun

Viewing 3 replies - 1 through 3 (of 3 total)
  • Thread Starter BaalOrun

    (@baalorun)

    Is this possible with any kind of code? please help me ??

    Thread Starter BaalOrun

    (@baalorun)

    i found another code and changed it a bit now it displays the latest post but the excerptimage isnt showed right…

    <?php
    $gen1_ids = 128;
    $gen2 = $wpdb->get_col("SELECT ID FROM $wpdb->posts WHERE $wpdb->posts.post_parent IN ($gen1_ids) AND $wpdb->posts.post_type = 'page' AND $wpdb->posts.post_status = 'publish' ORDER BY $wpdb->posts.ID ASC");
    $gen2_ids = implode($gen2,', ');
    $gen3 = $wpdb->get_col("SELECT ID FROM $wpdb->posts WHERE $wpdb->posts.post_parent IN ($gen2_ids) AND $wpdb->posts.post_type = 'page' AND $wpdb->posts.post_status = 'publish' ORDER BY $wpdb->posts.ID ASC");
    $gen3_ids = implode($gen3,', ');
    $args=array(
      'post__in' => $gen3,
      'post_type' => 'page',
      'post_status' => 'publish',
      'posts_per_page' => 1,
      'orderby' => 'modified',
      'order' => 'DESC'
    );
    $my_query = null;
    $my_query = new WP_Query($args);
    if( $my_query->have_posts() ) {
      while ($my_query->have_posts()) : $my_query->the_post(); ?>
    <div class="green2">
    			<h1><?php the_title(); ?></h1>
    			<?php the_excerpt(); ?>
    			<a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>">weiterlesen...</a>
    </div>
        <?php
      endwhile;
    }
    wp_reset_query();  // Restore global post data stomped by the_post().
    
    ?>
    Thread Starter BaalOrun

    (@baalorun)

    Thanks for the Help NOT

    I found out myself so for everyone who wants to do the same here is the code

    <?php
    $gen1_ids = 128;
    $gen4_ids = 144;
    $gen2 = $wpdb->get_col("SELECT ID FROM $wpdb->posts WHERE $wpdb->posts.post_parent IN ($gen1_ids,$gen4_ids) AND $wpdb->posts.post_type = 'page' AND $wpdb->posts.post_status = 'publish' ORDER BY $wpdb->posts.ID ASC");
    $gen2_ids = implode($gen2,', ');
    $gen3 = $wpdb->get_col("SELECT ID FROM $wpdb->posts WHERE $wpdb->posts.post_parent IN ($gen2_ids) AND $wpdb->posts.post_type = 'page' AND $wpdb->posts.post_status = 'publish' ORDER BY $wpdb->posts.ID ASC");
    $gen3_ids = implode($gen3,', ');
    $args=array(
      'post__in' => $gen3,
      'post_type' => 'page',
      'post_status' => 'publish',
      'posts_per_page' => 1,
      'orderby' => 'modified',
      'order' => 'DESC'
    );
    $my_query = null;
    $my_query = new WP_Query($args);
    if( $my_query->have_posts() ) {
      while ($my_query->have_posts()) : $my_query->the_post(); ?>
    <div class="green3">
    			<a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><h1><?php the_title(); ?></h1></a>
    			<a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php echo get_the_post_thumbnail($page->ID, 'thumbnail'); ?></a>
    			<?php the_advanced_excerpt('length=10&use_words=1&allowed_tags=_all'); ?>
    			<div style="padding-top:15px;"><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>">weiterlesen...</a></div>
    </div>
        <?php
      endwhile;
    }
    wp_reset_query();  // Restore global post data stomped by the_post().
    
    ?>

    It shows an excerpt with an image of the latest grandchildren of the two categories 128,144 you can add more categories or add more posts to the output by adding another var to the code.

    Maybe its useful for somebody

    Greetings Baal Orun

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘query post for childpages’ is closed to new replies.