0

I'm creating an authors.php page to display all the posts for the author clicked.

But the list(s) needs to show the very first / latest post so I can style it diferently than the rest of the posts?

I did think of just having 2 queries, one query just displaying the very first post, so I can style the thumbnail size, title size etc. in this loop;

<! -- Start the Loop . -->
<?php if(have_posts()) : while(have_posts()) : the_post(); ?>
    <h2><a href="<?php the_permalink() ?>" rel="bookmark"
           title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></h2>
    <?php the_post_thumbnail(); ?>
    <small><?php the_time('F jS, Y') ?> by <?php the_author_posts_link() ?></small>
    <?php the_excerpt();
endwhile;
endif;

Then another query minus the first post?

I'd like it done in a way so I can easily style it using divs etc. Does that make sense and is this possible?

0

There's no need for multiple queries - posts are, by default, ordered by most recent. Just apply a classname for the first post on the first page:

<article <?php post_class( $wp_query->current_post === 0 && ! is_paged() ? 'my-awesome-first-post' : '' ) ?> 

The first post of the first page will have the class my-awesome-first-post.

Update: Based on your updated question's code:

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

    <div <?php post_class( $wp_query->current_post === 0 && ! is_paged() ? 'first-post' : '' ) ?>>
        <h2><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></h2>
        <?php the_post_thumbnail();?>
        <small><?php the_time('F jS, Y') ?> by <?php the_author_posts_link() ?></small>

        <?php the_excerpt() ?>
    </div>

<?php endwhile ?>
  • Ahh OK so how could I fit this within a query; thanks for the help btw! – DJP2019 Jan 15 '16 at 14:03
  • Just put it in your loop in authors.php – TheDeadMedic Jan 15 '16 at 14:06
  • Tried adding that to my query but no luck; would it be possible to wrap the first post in a div titled first-post? – DJP2019 Jan 15 '16 at 14:14
  • See my revised answer. – TheDeadMedic Jan 15 '16 at 14:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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