Hi i'm trying to adopt the get_template_part() method for looping post formats as in:

if ( have_posts() ) :
    while ( have_posts() ) : the_post();
        if( ! get_post_format() ) {
            get_template_part( 'format', 'standard' );
        } else {
            get_template_part( 'format', get_post_format() );

The theme i'm developing from see files has an index.php file with the following calls

 * @package WordPress
 * @subpackage WP-Skeleton

    get_header();  //the Header

    get_template_part( 'menu', 'index' ); //the  menu + logo/site title 

    get_template_part( 'loop', 'index' ); //the Loop  

    get_template_part( 'sidebar', 'index' ); //the Sidebar 

    get_footer(); //the Footer 


loop.php is the main loop.

I'm not sure if I have to modify the index.php or loop.php files. I realise I have to create format-audio.php, format-video.php etc. for my various formats.

Whenever I try to get this going I get a continous loop of my posts.

Any help explaining this would be appreciated.

Many thanks

1 Answer 1


You have to edit format.php & format-type.php files according to your get_template_part() usage.

  • Hi thanks for your comment. Where do I put the get_template_part('format', get_post_format()); Does it replace get_template_part( 'loop', 'index' ); //the Loop ?
    – James
    Jan 8, 2012 at 17:15
  • I would put the first code snippet you provided, which seems to be valid, in the index.php file (after get_header and before get_footer functions). Then I would create format.php (which would be for standard posts). Replace get_template_part( 'format', 'standard' ); with get_template_part( 'format '); and create format-type.php for each format. This way you don't even need loop.php.
    – Asko
    Jan 8, 2012 at 17:25
  • I presume the format.php and format-type.php do not have to include the loop?
    – James
    Jan 8, 2012 at 17:35
  • I've tryed your suggestion but am getting the continuous loop i.e its on an endless loop through my two test posts?
    – James
    Jan 8, 2012 at 17:38
  • No loop. Just that first snippet you provided with the get_header and get_footer and the format & format-type.php files. Inside the format files, do not start a new loop, just start by echoing <?php the_title(); ?> for example, you'll get the hang of it.
    – Asko
    Jan 8, 2012 at 18:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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