• I’m working on a design that will have the blog content displayed on the right column, and the current page content displayed on the left. I was pointed in the direction of used multiple loops to pull this off, but I am having trouble determining exactly how to use multiple loops to pull it off. I could use some more guidance on how I can pull this off.
    Thank you!

Viewing 3 replies - 1 through 3 (of 3 total)
  • This will list all pages and all posts

    <?php
    $types[0] = 'page';
    $types[1] = 'post';
    
    foreach ($types as $type) {
      $args=array(
        'post_type' => $type,
        'post_status' => 'publish,future',
        'showposts' => -1,
        'caller_get_posts'=> 1
        );
      $my_query = null;
      $my_query = new WP_Query($args);
      if( $my_query->have_posts() ) {
        echo 'List of: ' . $type .'(s)';
        while ($my_query->have_posts()) : $my_query->the_post(); ?>
          <p><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></p>
         <?php
        endwhile;
      } //if ($my_query)
    } // foreach
    wp_reset_query();  // Restore global post data stomped by the_post().
    ?>

    Thread Starter rybarnes

    (@rybarnes)

    I’m not the best PHP user. I tried to modify the code you gave me, but failed. How can I use the code to display a single pages content, and the blog posts? I’m looking to have the blog content appear next to the currently loaded page.

    Okay then two looks, the first display page id 27, then 2nd one displays all posts:

    <?php
    $args=array(
      'page_id' =>27,
      'post_type' => 'page',
      'post_status' => 'publish',
      'posts_per_page' => 1,
      'caller_get_posts'=> 1
    );
    $my_query = null;
    $my_query = new WP_Query($args);
    if( $my_query->have_posts() ) {
      echo 'List of Page ID 27';
      while ($my_query->have_posts()) : $my_query->the_post(); ?>
        <p><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></p>
        <?php
      endwhile;
    }
    wp_reset_query();  // Restore global post data stomped by the_post().
    
    $args=array(
      'post_type' => 'post',
      'post_status' => 'publish',
      'posts_per_page' => -1,
      'caller_get_posts'=> 1
    );
    $my_query = null;
    $my_query = new WP_Query($args);
    if( $my_query->have_posts() ) {
      echo 'List of All Posts';
      while ($my_query->have_posts()) : $my_query->the_post(); ?>
        <p><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></p>
        <?php
      endwhile;
    }
    wp_reset_query();  // Restore global post data stomped by the_post().
    ?>

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Displaying Blog Posts and Page content on a single page’ is closed to new replies.