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'm working with a company's About page. I created a custom post type for "Employees", and am using the Advanced Custom Fields plugin to create simple meta boxes for name, title, image, and bio.

The first employee listed is the owner, and i'd like to style his bio differently from the rest, but my php skills aren't quite up to the task.

Here is the code i'm working with so far, I just need to understand how to create a variable for the first post in the array and style it differently.

<?php
    $args = array('post_type' => 'employee');
    $employee= new WP_Query( $args );
    if( $employee->have_posts() ) {
    while( $employee->have_posts() ) {
    $employee->the_post();
    ?>

    <div <?php post_class('portrait'); ?>>
        <img src="<?php the_field('employee_photo'); ?>" alt="" />
        <h3><?php the_title() ?></h3>
        <span><?php the_field('employee_title'); ?></span>
        <p><?php the_field('employee_bio'); ?></p>
    </div>

    <?php
    }
        }
        else { ?>
            <div class="portrait">
            <img src="<?php the_field('employee_photo'); ?>" alt="" />
            <h3><?php the_title() ?></h3>
            <span><?php the_field('employee_title'); ?></span>
            <p><?php the_field('employee_bio'); ?></p>
            </div>
    <?php } ?>
share|improve this question
add comment

1 Answer

You can check current_post in the loop. Just remember it's zero-indexed, so first is 0, second is 1, etc.:

if( 0 == $employee->current_post ):
    // this is the first post
else:
    // this is > first post
endif;
share|improve this answer
    
I understand that concept, but I'm not sure where to place that code without erring out my server, given the code block I pasted above. –  joshlawler7 Jan 11 '13 at 16:35
    
I ended up figuring out this solution, with some extra help from this thread: link –  joshlawler7 Jan 11 '13 at 17:02
1  
@joshlawler7, would be nice if you added your own Answer with the solution, this meta item may help: How does accepting an answer work?. –  brasofilo Jan 12 '13 at 15:51
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.