• Resolved kevin_curry

    (@kevin_curry)


    The site I’m working on is ZipRage. Basically I would like to modify the theme to give it more of a magazine style layout and this requires working with multiple loops which is throwing me for a loop. Here is what I want to do. I would like the most recent post to show in full on the home page only, then I would like to show the second two posts as excerpts finally beneath that two posts per category in two columns. To Illustrate:

    | Full Post |
    | Excerpt |
    | Excerpt |
    |Cat 1 ||Cat 1 |
    |Cat 2 ||Cat 2 |
    |Cat 3 ||Cat 3 |
    |Cat 4 ||Cat 4 |

    Any guidance is very much appreciated. I’m pretty confident I can handle the CSS/XHTML work required to make the columns look good I just need help creating the loop. Thanks.

Viewing 7 replies - 1 through 7 (of 7 total)
  • <?php
    // get threee posts, display content for first, excerpt fot the other two
    $count = 0;
    $args=array(
      'post_type' => 'post',
      'post_status' => 'publish',
      'posts_per_page' => 3,
      'caller_get_posts'=> 1
    );
    $my_query = null;
    $my_query = new WP_Query($args);
    if( $my_query->have_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
        $count++;
        if ( $count < 2 ) {
          the_content('Read the rest of this entry &raquo;');
        } else {
          the_excerpt();
        }
      endwhile;
    }
    wp_reset_query();  // Restore global post data stomped by the_post().
    ?>
    <?php
    //get all categories and display two posts from each category
    $taxonomy = 'category';
    $param_type = 'category__in';
    $term_args=array(
      'orderby' => 'name',
      'order' => 'ASC'
    );
    $terms = get_terms($taxonomy,$term_args);
    if ($terms) {
      foreach( $terms as $term ) {
        $args=array(
          "$param_type" => array($term->term_id),
          'post_type' => 'post',
          'post_status' => 'publish',
          'posts_per_page' => 2,
          'caller_get_posts'=> 1
          );
        $my_query = null;
        $my_query = new WP_Query($args);
        if( $my_query->have_posts() ) {
          $count = 0;
          echo 'List of Posts in '.$taxonomy .' '.$term->name;
          while ($my_query->have_posts()) : $my_query->the_post();
          $count++;
          if ( $count < 2 ) {  ?>
          <!---handle column 1 here --->
          <?php
        } else { ?>
          <!---handle column 2 here --->
        <?php
         }
         ?>
         <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().
    ?>
    Thread Starter kevin_curry

    (@kevin_curry)

    That’s amazing thank you very much! One other question using this the navlink which takes you to the next page will display the next page which is exactly the same as the first. Can you make the above code conditional for the front page only and then every page after that would just be the category columns with posts ordered by date?

    Thread Starter kevin_curry

    (@kevin_curry)

    One more question. If I wanted to show a selection of categories instead of all of them would I just add to the $args=array(
    ‘include’ => 1,2,etc..?

    Can you make the above code conditional for the front page

    Wrap that first loop in a Conditional Tag such as

    <?php
    // get threee posts, display content for first, excerpt for the other two
    if (is_home()) {
    $count = 0;
    
    ///first loop here
    
    wp_reset_query(); // Restore global post data stomped by the_post().
    }
    ?>

    If I wanted to show a selection of categories

    $term_args=array(
    'orderby' => 'name',
    'order' => 'ASC',
    'include' => '71,22,3'
    );

    Thread Starter kevin_curry

    (@kevin_curry)

    Are you a volunteer or do you get paid for this awesome help. I ended up using the following code to just show my layout on the front page:

    <?php
    // create first page content
    $paged = get_query_var(‘paged’);
    if ($paged < 2): ?>

    Huge thanks for the second code I couldn’t get it to work for the life of me today. You cleared up a huge headache.

    Except for automattic.com employess, the rest of us are volunteers.

    Good luck. Will mark this resolved.

    Greetings Guys,

    Foremost, allow me to thank Kevin_Curry for the straight forward question, and also to thank MichaelH for the code and explanation.

    I’ve been caught up in a similar bind { trying to implement a custom front page layout : Carousel/ Slideshow from Category 1, then a 3-Col Horizontal Sequence of posts { limited to either 3, or 6 }, from a second category.

    MichaelH’s code works perfect { pulling posts from all categories, and sequencing posts into two columns }. How can this code be adapted for use in the 3 column setup described above?

    Cheers
    Q

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Need Help Working With Multiple Loops’ is closed to new replies.