Ask your WordPress questions! Pay money and get answers fast! Comodo Trusted Site Seal
Official PayPal Seal

Magazine Styled Homepage (Multiple Loops, Queries, & Outputs) WordPress

  • SOLVED

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!

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

<strong>PAGE 1</strong>

<em>Featured Posts -</em>
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)

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

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

<em>Display WP Pagination</em>


<strong>PAGE 2</strong>

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

<em>Display the rest of the posts (10)</em>

<em>Display WP Pagination</em>

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

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:

[[LINK href="http://pastie.org/1111806"]]Code Here[[/LINK]]

Answers (3)

2010-08-24

Baki Goxhaj answers:

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 :)


Aaron comments:

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!

2010-08-24

Monster Coder answers:

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

2010-08-24

Ashfame answers:

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(); ?>


Ashfame comments:

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 <strong>featured</strong> tag


Ashfame comments:

Sorry this is the code :
query_posts(array('tag__not_in' => array(34)));


Aaron comments:

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


Ashfame comments:

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


Ashfame comments:

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'); ?>