Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I hope i can explain this right , what im trying to do is use the default word press loop to show all my posts etc.. but for the first post I would like it to be styled completely different depending on what parent category it was published in, so there would be a lot going on in that first post.

Right now I'm some what achieving this by using 2 loops that both pull from the default, the first loop is my "new / Featured" post area and is set to posts_per_page=1 , then the second loop is your standard loop, but the issue I'm having is obviously it shows duplicate posts, now i tried offset=1 on the second loop but then my pagination does not work, any help or direction would be awesome, I know its a lot sorry. below is my code for both loops and a link to my testing site thanks!

1st (new / featured) loop :

<?php $custom_query = new WP_Query('posts_per_page=1'); 
while($custom_query->have_posts()) : $custom_query->the_post(); ?>
<?php
$parent_cat = array();
$post_cats = get_the_category($post->ID);
foreach( $post_cats as $post_cat ) {
if( $post_cat->parent ) $parent_cat[] = get_category( $post_cat->parent )->slug;
}
?>

<!--CONTENT HERE-->


<?php endwhile; ?>
<?php wp_reset_postdata(); // reset the query ?>
<?php } else { ?>

2nd (Standard) loop:

<?php if (have_posts()) : ?>
<?php while (have_posts()) : the_post(); ?>

<!--CONTENT HERE-->


<?php endwhile; else: ?>
<?php _e('Sorry, no posts matched your criteria.'); ?>
<?php endif; ?>

Here is a link to the dev site were you can see what im talking about http://themes.thefragilemachine.com/gone/

thanks for any help!

share|improve this question

2 Answers 2

up vote 2 down vote accepted

one loop with a conditional statement to catch the first post should work; example:

<?php if( $wp_query->current_post == 0 && !is_paged() ) : ?>
/*the output of the first post*?
<?php else : ?>
/*the output of all other posts*/
<?php endif; ?>
share|improve this answer
    
Also check if is_archive() or !is_singular() to make sure the page does not have a single post. Don't know if is_paged() has same effect. –  EarnestoDev Oct 26 '11 at 16:57
    
this seems to be working but it is only showing 1 post, and no excerpt , themes.thefragilemachine.com/gone , I did noticed I do have is_paged() –  The Fragile Machine Oct 26 '11 at 17:11
    
ahhh just got this to work thank you!!! amazing! –  The Fragile Machine Oct 26 '11 at 17:54

Just add a variable that will work just once with PHP like this for example:

<?php $custom_query = new WP_Query('posts_per_page=1'); 
$i = 0; while($custom_query->have_posts()) : $custom_query->the_post(); ?>

<?php if($i==0){ 

// do - echo whatever you want 

$i++; 

} else { 

// rest of the posts

} ?>  

<?php endwhile; ?>
<?php wp_reset_postdata(); // reset the query ?>
share|improve this answer
    
thanks Ill give this a try! –  The Fragile Machine Oct 26 '11 at 17:17
    
hmm.. Im getting a syntax error on this –  The Fragile Machine Oct 26 '11 at 17:27

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.