logo

$10
Magazine Styled Homepage (Multiple Loops, Queries, & Outputs)

I need some help with a magazine theme homepage I am building. The scenario is below and the current code base is linked at the bottom. Please help me figure out what the best and most efficient way is to do this. Thanks!

-------------------------------------

PAGE 1

Featured Posts -
Grab the 5 most recent posts with the tag 'featured', and display.

(Now remove the top 5 most recent featured posts from the query/loop below to not duplicate content)

Column Posts -
Display the first 4 posts with a different class, and different arrangements of elements.

Small Posts -
Display 6 posts with a different class then above, and different arrangements of elements then above.

Display WP Pagination


PAGE 2

(Also remove the top 5 most recent featured posts from the query/loop)

Display the rest of the posts (10)

Display WP Pagination

-------------------------------------

So far I have this as my home.php, but am not sure if this is the best and most efficient way to do this:

Code Here

Aaron | 08/24/10 at 4:10am | Edit


(3) Possible Answers Submitted...

  • avatar
    Last edited:
    08/24/10
    4:23am
    Monster Coder says:

    quick tips (i will try to come with details a bit later, busy now). to reset query use

    wp_reset_query();

  • avatar
    Last edited:
    08/24/10
    4:39am
    Ashfame says:

    Ok!

    This is for query posts tagged as featured :

    <?php query_posts('tag=featured'); ?>


    Reset it before querying again:
    <?php wp_reset_query(); ?>


    For different arrangement, just use different class in a regular WordPress loop.

    For Page navigation, use this plugin - http://wordpress.org/extend/plugins/wp-pagenavi/
    and use this to output the page navigation :
    <?php wp_pagenavi(); ?>

    Previous versions of this answer: 08/24/10 at 4:44am

    • 08/24/10 4:43am

      Ashfame says:

      And to query again excluding the posts tagged as featured :

      <?php query_posts(array('tag__in' => array(34))); ?>


      Replace 34 with the ID of the featured tag

    • 08/24/10 4:45am

      Ashfame says:

      Sorry this is the code :

      query_posts(array('tag__not_in' => array(34)));

    • 08/24/10 4:49am

      Aaron says:

      This does not exclude ONLY the first 5 posts with the tag of 'featured', but rather all posts with the tag of 'featured'.

    • 08/24/10 4:51am

      Ashfame says:

      The page 2 you are referring here is the actual page 2 or another page and you just named it page 2?

    • 08/24/10 4:52am

      Ashfame says:

      If this is not a regular page 2 and you are doing it on a different page, then you can set the offset parameter to leave first X posts by this code :

      <?php query_posts('posts_per_page=5&offset=1'); ?>

  • avatar
    Last edited:
    08/24/10
    5:47am
    Baki Goxhaj says:

    Here is the as-intended working sample of your code:



    <div id="showcase">

    <?php $my_query = new WP_Query('tag=featured&showposts=5');
    while ($my_query->have_posts()) : $my_query->the_post();
    $do_not_duplicate[] = $post->ID; ?>

    <div class="slide">
    <div class="post-img-large fl"><?php the_post_thumbnail('large'); ?></div>
    <h2 class="post-title fl"><a href="<?php the_permalink(); ?>" rel="bookmark" title="<?php the_title_attribute(); ?>"><?php the_title(); ?></a></h2>
    <div class="post-comments fr"><?php comments_popup_link('0', '1', '%'); ?></div>
    <p class="post-meta fl"><?php the_time('F jS, Y'); ?>, In <?php the_category(', '); ?>, by <?php the_author_posts_link(); ?></p>
    <div class="clear"></div>
    </div><!--slide-->

    <?php endwhile; ?>



    <div class="tabs">

    <?php while ($my_query->have_posts()) : $my_query->the_post(); ?>
    <a href="<?php the_permalink(); ?>" rel="bookmark" title="<?php the_title_attribute(); ?>"><div class="post-img-tiny"><?php the_post_thumbnail('tiny'); ?></div><h6><?php the_title(); ?></h6></a>
    <?php endwhile; ?>

    </div><!--tabs-->
    </div><!--showcase-->


    <?php // HALF COLUMN POSTS: Display The First 4 Posts ?>
    <?php query_posts('showposts=4'); ?>
    <?php if (have_posts()) : while (have_posts()) : the_post(); if( in_array($post->ID, $do_not_duplicate) ) continue; ?>

    <div class="post half fl">
    <div class="post-img-medium fl"><?php the_post_thumbnail('medium'); ?></div>
    <h2 class="post-title fl"><a href="<?php the_permalink(); ?>" rel="bookmark" title="<?php the_title_attribute(); ?>"><?php the_title(); ?></a></h2>
    <p class="post-excerpt fl"><?php the_excerpt(); ?></p>
    <p class="post-meta fl"><?php the_time('F jS, Y'); ?>, In <?php the_category(', '); ?>, by <?php the_author_posts_link(); ?></p>
    <div class="post-comments fr"><?php comments_popup_link('0', '1', '%'); ?></div>
    <div class="clear"></div>
    </div><!--post(half)-->

    <?php endwhile; endif; ?>


    <?php // SMALL POSTS: Display The Remaining 5 Posts ?>
    <?php query_posts('showposts=5'); ?>
    <?php if (have_posts()) : while (have_posts()) : the_post(); if( in_array($post->ID, $do_not_duplicate) ) continue; ?>

    <div class="post small fl">
    <div class="post-img-small fl"><?php the_post_thumbnail('small'); ?></div>
    <h2 class="post-title fl"><a href="<?php the_permalink(); ?>" rel="bookmark" title="<?php the_title_attribute(); ?>"><?php the_title(); ?></a></h2>
    <div class="post-comments fr"><?php comments_popup_link('0', '1', '%'); ?></div>
    <p class="post-meta fl"><?php the_time('F jS, Y'); ?>, In <?php the_category(', '); ?>, by <?php the_author_posts_link(); ?></p>
    <p class="post-excerpt fl"><?php the_excerpt(); ?></p>
    <div class="clear"></div>
    </div><!--post(small)-->

    <?php endwhile; endif; ?>


    Waiting for feedback :)

    • 08/24/10 5:47am

      Aaron says:

      Great, I just added and offset of 4 to the last query and a closing end if to the end and it's good, thanks!

This question has expired.





Current status of this question: Completed