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.

  • 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 Aug 20 '14 at 2:14
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;
| improve this answer | |
  • 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 Aug 20 '14 at 2:15
  • Seems that's what the OP wants. – cfx Aug 20 '14 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 Aug 20 '14 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! – William Guy Aug 20 '14 at 4:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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