0

I currently have the following php code for the content loop on my homepage.

<?php
        if ( have_posts() ) :
            // Start the Loop.
            while ( have_posts() ) : the_post();

                get_template_part( 'content', get_post_format()  );

            endwhile;

            twentyfourteen_paging_nav();

        else :

            get_template_part( 'content', 'none' );

        endif;
    ?>

I want to know how I can specifically select one post format. I want the loop to only display posts of the standard post format.

1
  • Can you be more specific? Your post would make more sense if you were using WP_Query, but you aren't, can you clarify some more? A post loop could mean any and all archives, posts, pages, homepage, etc, e.g. only showing standard format posts on the homepage etc Where would you want this limitation to apply?
    – Tom J Nowell
    Commented Aug 20, 2014 at 2:14

1 Answer 1

0

Use get_post_format() inside your loop:

if (have_posts()) :
  while (have_posts()) :
    the_post();
    $format = get_post_format();
    if (false === $format) {
      get_template_part('content', get_post_format());
    }
  endwhile;
  twentyfourteen_paging_nav();
else :
  get_template_part('content', 'none');
endif;
4
  • If the page contains only gallery or image posts then this code will give an archive page with no posts on it
    – Tom J Nowell
    Commented Aug 20, 2014 at 2:15
  • Seems that's what the OP wants.
    – cfx
    Commented Aug 20, 2014 at 2:28
  • Not if this is page 2 of 5, I would expect to see 4 pages instead of 5 with a completely empty archive page on page 2
    – Tom J Nowell
    Commented Aug 20, 2014 at 3:43
  • Sorry for not clearing it up. This is only for my main index page - I did not want asides, images or quotes showing up in the feed. Cfx you did exactly what I wanted. Thank you! Commented Aug 20, 2014 at 4:41

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.