Title: Custom Loop &#8211; Get Post Format
Last modified: August 21, 2016

---

# Custom Loop – Get Post Format

 *  Resolved [mak1wp](https://wordpress.org/support/users/mak1wp/)
 * (@mak1wp)
 * [13 years, 1 month ago](https://wordpress.org/support/topic/custom-loop-get-post-format/)
 * Hi,
 * I’ve created a custom loop template for the purpose of displaying the posts in
   various grid layouts. But I’m not sure how to specify the **Post Format** ie 
   standard, quote, link, image.
 * The standard post loop (index.php) which works to pull in the post format looks
   like this..
 *     ```
       <?php if ( have_posts() ) : ?>
   
       				<?php while ( have_posts() ) : the_post(); ?>
   
       					<?php get_template_part( 'content', get_post_format() ); ?>
   
       				<?php endwhile; ?>
   
       			<?php else : ?>
       				<?php get_template_part( 'content', 'none' ); ?>
       			<?php endif; ?>
       ```
   
 * The custom one I’ve put together works like this…
 *     ```
       <div class="six columns">
   
       			<?php if ( have_posts() ) : ?>
   
                       <?php while ( have_posts() ) : the_post(); ?>
   
                       	<a href="<?php the_permalink() ?>" >   <?php the_post_thumbnail('the-hub-image', array('class' => 'alignleft')); ?></a>
   
                           <h2 class="postTitle"><a href="<?php the_permalink() ?>" rel="bookmark"><?php the_title(); ?></a></h2>
       ```
   
 * … and goes on to specify the other features/layout I need.
 * Is there any way to include the `get_post_format` in this custom layout loop 
   in order to load the various different layout styles for post formats which aren’t
   marked as ‘standard’ post?
 * Many thanks in advance to any replies!

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

 *  [Michael](https://wordpress.org/support/users/alchymyth/)
 * (@alchymyth)
 * [13 years, 1 month ago](https://wordpress.org/support/topic/custom-loop-get-post-format/#post-3693116)
 * you could try to use `get_template_part()` together with a selection of various
   templates as in the default code;
 * or use a number of ‘if/elseif/else’ structures;
 * example:
 *     ```
       <?php if ( have_posts() ) : ?>
   
                       <?php while ( have_posts() ) : the_post(); ?>
   
       <?php if( get_post_format() == 'quote' ) : ?>
       ANY OUTPUT FOR QUOTE POSTS
       <?php elseif( get_post_format() == 'link' ) : ?>
       ANY OUTPUT FOR LINK POSTS
       <?php else : ?>
       ANY OUTPUT FOR STANDARD POSTS
       <?php endif; ?>
   
       <?php endwhile;
       endif; //closing of the loop ?>
       ```
   
 *  Thread Starter [mak1wp](https://wordpress.org/support/users/mak1wp/)
 * (@mak1wp)
 * [13 years, 1 month ago](https://wordpress.org/support/topic/custom-loop-get-post-format/#post-3693125)
 * Amazing, thanks so much for your help [@alchymyth](https://wordpress.org/support/users/alchymyth/)
   that worked an absolute charm!
 *  [Audee](https://wordpress.org/support/users/graphicidentity/)
 * (@graphicidentity)
 * [12 years, 5 months ago](https://wordpress.org/support/topic/custom-loop-get-post-format/#post-3693359)
 * [@alchymyth](https://wordpress.org/support/users/alchymyth/) big thanks to you!
 * The ‘if/elseif/else’ structures have saved me from major headache to figure out
   how to keep the post format icon showing up for different layout of categories.
 * I couldn’t do more with the content.php since my category-custom.php has a very
   different layout than the category.php

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

The topic ‘Custom Loop – Get Post Format’ is closed to new replies.

## Tags

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

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 3 replies
 * 3 participants
 * Last reply from: [Audee](https://wordpress.org/support/users/graphicidentity/)
 * Last activity: [12 years, 5 months ago](https://wordpress.org/support/topic/custom-loop-get-post-format/#post-3693359)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
