-1

This question already has an answer here:

I need to show 7 posts of a certain category.

The first needs to appear as Title / Date / Excerpt.

While the others can just be Titles of the posts.

Right now I am having trouble with getting the first post to appear different with my specific code.

Any help would be appreciated, thanks.

<?php $the_query = new WP_Query( 'showposts=7&cat=113' ); ?>
<?php while ($the_query -> have_posts()) : $the_query -> the_post(); ?>
<strong><a href="<?php the_permalink() ?>"><?php the_title(); ?></a></strong>
<hr size="1" color="#919191">
<?php endwhile;?>

marked as duplicate by Michael, Pieter Goosen, TheDeadMedic, Mark Kaplun, Sisir Aug 27 '15 at 4:48

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

0

In your loop, you can use a variable to check, in this case $i, so the code will belong to:

  <?php $the_query = new WP_Query( 'showposts=7&cat=113' ); ?>
    <?php while ($the_query->have_posts()) : $the_query->the_post(); ?>
    <strong><a href="<?php the_permalink() ?>"><?php the_title(); ?></a></strong>
    <hr size="1" color="#919191">
    <?php endwhile;?>


    <?php $the_query = new WP_Query( 'showposts=7&cat=113' ); ?>
    <?php $i = 0; while ($the_query->have_posts()) : $the_query->the_post();
    $i++;

    // First post
    if ( $i === 1 ) : ?>
        <strong><a href="<?php the_permalink() ?>"><?php the_title(); ?></a></strong>
        <p><?php the_excerpt(); ?></p>
    <?php else : 
    // Other posts ?>
        <strong><a href="<?php the_permalink() ?>"><?php the_title(); ?></a></strong>
        <hr size="1" color="#919191">
        <?php 
    endif;
    endwhile;
    ?>

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