Title: format first recent custom post differently
Last modified: August 20, 2016

---

# format first recent custom post differently

 *  [sdesigns](https://wordpress.org/support/users/sdesigns/)
 * (@sdesigns)
 * [13 years, 1 month ago](https://wordpress.org/support/topic/format-first-recent-custom-post-differently/)
 * I am trying to show the 5 most recent posts from a custom post type but to have
   the thumbnaiul and excerpt show up on the first post but not the rest. The code
   I have below works for this but it is putting the Title for the first post below
   the excerpt.
 * Thank you
 *     ```
       \\<?php $recent = new WP_Query('post_type=outtakes&posts_per_page=5' ); ?>
       <?php $is_first_post = true; ?>
   
       <?php while( $recent->have_posts() ) : $recent->the_post(); ?>
   
                <?php
                       if ( $is_first_post  && has_post_thumbnail() ) {
                           the_post_thumbnail('medium'); echo excerpt(25);
   
                           $is_first_post = false;
                       }
                       ?>
   
       <ul>
       <li>
                 <a>">
                       <?php the_title(); ?>
                       </a>
   
       </li>
       </ul>
       <?php endwhile; ?>\\
       ```
   
 * _[ [http://codex.wordpress.org/Forum\_Welcome#Posting\_Code](http://codex.wordpress.org/Forum_Welcome#Posting_Code)–
   the above code is partly broken because it was posted unmarked]_

Viewing 8 replies - 1 through 8 (of 8 total)

 *  [Josh](https://wordpress.org/support/users/josh401/)
 * (@josh401)
 * [13 years, 1 month ago](https://wordpress.org/support/topic/format-first-recent-custom-post-differently/#post-3613422)
 * That’s pretty messy. Let’s try something easy to make sure it works first:
 *     ```
       <?php 
   
       $recent = new WP_Query('post_type=outtakes&posts_per_page=5' ); 
   
       while( $recent->have_posts() ) : $recent->the_post();
           if ( $is_first_post && has_post_thumbnail() ) {
               the_post_thumbnail('medium'); echo excerpt(25);
           } else {
               the_title();
           }
       endwhile;
   
       ?>
       ```
   
 *  Thread Starter [sdesigns](https://wordpress.org/support/users/sdesigns/)
 * (@sdesigns)
 * [13 years, 1 month ago](https://wordpress.org/support/topic/format-first-recent-custom-post-differently/#post-3613432)
 * I just tried that and it just gives me the first post excerpt with no image, 
   title and no link to read more. It also is not putting out the other 4 items.
 * Thank you
 *  [Josh](https://wordpress.org/support/users/josh401/)
 * (@josh401)
 * [13 years, 1 month ago](https://wordpress.org/support/topic/format-first-recent-custom-post-differently/#post-3613443)
 * Oops.. that’s my mistake. I was taking some of your code from the original that
   you posted.
 * Change this:
    `if ( $is_first_post && has_post_thumbnail() ) {`
 * To this:
    `if ( is_first_post() && has_post_thumbnail() ) {`
 *  Thread Starter [sdesigns](https://wordpress.org/support/users/sdesigns/)
 * (@sdesigns)
 * [13 years, 1 month ago](https://wordpress.org/support/topic/format-first-recent-custom-post-differently/#post-3613458)
 * I used the below code and now I get an error
 * Fatal error: Call to undefined function is_first_post() in /home/XXXXXX/public_html/
   wp-content/themes/XXXXXX/myhomepage.php on line 46
 *  Thank you
 *  /<?php
 * $recent = new WP_Query(‘post_type=outtakes&posts_per_page=5’ );
 * while( $recent->have_posts() ) : $recent->the_post();
    if ( is_first_post() &&
   has_post_thumbnail() ) { the_post_thumbnail(‘medium’); echo excerpt(25); } else{
   the_title(); } endwhile;
 * ?>/
 * _[please read and apply the forum guidelines for posting code – [http://codex.wordpress.org/Forum\_Welcome#Posting\_Code](http://codex.wordpress.org/Forum_Welcome#Posting_Code)]_
 *  Moderator [keesiemeijer](https://wordpress.org/support/users/keesiemeijer/)
 * (@keesiemeijer)
 * [13 years, 1 month ago](https://wordpress.org/support/topic/format-first-recent-custom-post-differently/#post-3613461)
 * Can you try it with this:
 *     ```
       <?php
   
       $recent = new WP_Query( 'post_type=outtakes&posts_per_page=5' );
   
       while ( $recent->have_posts() ) : $recent->the_post();
       if ( $recent->current_post == 0 ) {
       	if ( has_post_thumbnail() ) {
       		the_post_thumbnail( 'medium' );
       	}
       	echo excerpt( 25 );
       } else {
       	the_title();
       }
       endwhile;
   
       ?>
       ```
   
 * is `excerpt(25)` a function in your theme?
 *  Thread Starter [sdesigns](https://wordpress.org/support/users/sdesigns/)
 * (@sdesigns)
 * [13 years, 1 month ago](https://wordpress.org/support/topic/format-first-recent-custom-post-differently/#post-3613463)
 * Getting closer. It is showing the first image and excerpt but the title is not
   clickable and their is now More>> at the end of the excerpt.
 * The rest ot the titles are coming in but they are right next to each other not
   an unordered list and are not clickable.
 * Thank you for you help.
 * /
    <?php
 * $recent = new WP_Query( ‘post_type=outtakes&posts_per_page=5’ );
 * while ( $recent->have_posts() ) : $recent->the_post();
    if ( $recent->current_post
   == 0 ) { if ( has_post_thumbnail() ) { the_post_thumbnail( ‘medium’ ); } echo
   the_title(); echo excerpt( 25 ); } else { echo the_title();
 * }
    endwhile;
 * ?>/
 *  Thread Starter [sdesigns](https://wordpress.org/support/users/sdesigns/)
 * (@sdesigns)
 * [13 years, 1 month ago](https://wordpress.org/support/topic/format-first-recent-custom-post-differently/#post-3613472)
 * I also found another code that is almost working but this one is not removing
   the excerpt from the rest of the items.
 * /
    <?php $c = 0; $blog_query = new WP_Query(‘post_type=outtakes&posts_per_page
   =5’); while ($blog_query->have_posts()) : $blog_query->the_post();?>
 * <div <?php if( $c ==0 ) post_class(‘special’); else post_class() ?> id=”post-
   <?php the_ID(); ?>”>
 * <?php if ( has_post_thumbnail()) : ?>
    ” title=”<?php the_title_attribute(); ?
   >” > <?php the_post_thumbnail(‘medium’); ?>  <?php endif; ?> <h3>” rel=”bookmark”
   title=”Permanent Link to <?php the_title_attribute(); ?>”><?php the_title(); ?
   ></h3>
 * <?php the_excerpt() ?>
 * </div><!–post–>
    <?php $c++;?> <?php endwhile; ?> /
 *  Thread Starter [sdesigns](https://wordpress.org/support/users/sdesigns/)
 * (@sdesigns)
 * [13 years, 1 month ago](https://wordpress.org/support/topic/format-first-recent-custom-post-differently/#post-3613482)
 * So far the code that seams to work the best is the one I was using at first but
   by two issues I am having with it still is that the image is not permalink so
   I can’t click on it and the Title is not above the excerpt it is below it and
   if I put it above the excert that title still shows in the bullet list.
    Any 
   help on this would be appreseated.
 * Thank you
 * /<?php $recent = new WP_Query(‘post_type=outtakes&posts_per_page=3’ ); ?>
    <?
   php $is_first_post = true; ?>
 * <?php while( $recent->have_posts() ) : $recent->the_post(); ?>
 *  <?php
    if ( $is_first_post && has_post_thumbnail() ) { the_post_thumbnail(‘medium’);
   echo excerpt(25);
 *  $is_first_post = false;
    } ?>
    - </h3>
 * <?php endwhile; ?>/

Viewing 8 replies - 1 through 8 (of 8 total)

The topic ‘format first recent custom post differently’ is closed to new replies.

## Tags

 * [custom post](https://wordpress.org/support/topic-tag/custom-post/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 8 replies
 * 3 participants
 * Last reply from: [sdesigns](https://wordpress.org/support/users/sdesigns/)
 * Last activity: [13 years, 1 month ago](https://wordpress.org/support/topic/format-first-recent-custom-post-differently/#post-3613482)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
