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.

Hi i'm using the code below to call post from a certain Category under certain post types, But how do i style it so that i can make the first post different from the rest of the post.

<?php
$queryObject = new  Wp_Query( array(
        'showposts' => 4,
        'post_type' => array('pretty-little-liars', 'revenge', 'once-upon-a-time'),
        'category_name' => celebrity,
            'orderby' => 1,
        ));
// The Loop!
if ($queryObject->have_posts()) {
?>

<?php
while ($queryObject->have_posts()){
    $queryObject->the_post();
    ?>

<a href="<?php the_permalink(); ?>" title="<?php printf(__( 'Read %s', 'wpbx' ), wp_specialchars(get_the_title(), 1)) ?>">
                    <?php the_post_thumbnail('video-post'); ?>
                    </a>

<?php echo human_time_diff( get_the_time('U'), current_time('timestamp') ) . ' ago'; ?>

               <a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>


<?php
}
?>
<?php wp_reset_postdata();
}
?>
share|improve this question
add comment

3 Answers

You could check current_post in the loop:

if($queryObject->have_posts()) {
    while($queryObject->have_posts()) {
        $queryObject->the_post();
        if( 0 == $queryObject->current_post ) {
            // this is the first post
        } else {
            // not the first post
        }
    }
}
share|improve this answer
    
didn't work...it made the whole sidebar disappear –  Mihad Aiko Jan 16 '13 at 6:38
    
we've been through this before- enable debugging and check for php errors, edit your question to show what you've tried. –  Milo Jan 16 '13 at 6:40
add comment

If you don't mind a little extra markup, you could wrap the first post in a div + use its class to style this post differently.

<?php
   $queryObject = new  Wp_Query( array(
        'showposts' => 4,
        'post_type' => array('pretty-little-liars', 'revenge', 'once-upon-a-time'),
        'category_name' => celebrity,
            'orderby' => 1,
        ));

  // The Loop
  if ( $queryObject->have_posts() ) :
      $i = 0;
      while ( $queryObject->have_posts() ) :
          $queryObject->the_post();
          ?>
          <?php if ( $i == 0 ) : ?>
              <div class="first-post">
          <?php endif; ?>
          <a href="<?php the_permalink(); ?>" title="<?php printf(__( 'Read %s', 'wpbx' ), wp_specialchars(get_the_title(), 1)) ?>">
              <?php the_post_thumbnail('video-post'); ?>
          </a>

          <?php echo human_time_diff( get_the_time('U'), current_time('timestamp') ) . ' ago'; ?>

          <a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
          <?php if ( $i == 0 ) : ?>
              </div>
          <?php endif; ?>    
          <?php $i++; ?>
      <?php endwhile; ?>
  <?php endif; ?>
share|improve this answer
add comment

You can do something like this:

        <?php
            $queryObject = new  Wp_Query( array(
                    'showposts' => 4,
                    'post_type' => array('pretty-little-liars', 'revenge', 'once-upon-a-time'),
                    'category_name' => celebrity,
                        'orderby' => 1,
                    ));

        // Initiate some counter to point the first post

        $post_counter = 0;

            // The Loop!
            if ($queryObject->have_posts()) {

            while ($queryObject->have_posts()){
                $queryObject->the_post();

        if(!$post_counter)
        {
                ?>

    /* Custom styling for the first post */       

            <?php
        }
    else
    {    
         /* common styling for the rest of the posts */    
    }

$post_counter+=1;

            }

         wp_reset_postdata();

            }

        ?>
share|improve this answer
add comment

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.