• Resolved mak1wp

    (@mak1wp)


    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

    (@alchymyth)

    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

    (@mak1wp)

    Amazing, thanks so much for your help @alchymyth that worked an absolute charm!

    Audee

    (@graphicidentity)

    @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.