0

When I visit a category page that lists all posts in that category, the divs that are to hold the content are empty. The template is clearly only set to display the standard post format, but none of the others (video, audio, quote, gallery, link).

How do I fix this?

Below is the contents of my category template:

<?php
    get_header();
    if ( have_posts() ) :
        while ( have_posts() ) : the_post();
            get_template_part( 'content', get_post_format() );
        endwhile;
        get_template_part( 'includes/navigation', 'index' );
    else:
        get_template_part( 'includes/no-results', 'index' );
    endif;
    get_footer();
?>

I also have template-part files for all the post formats, i.e. content-gallery.php

0

Reading the codex on get_template_part and get_post_format will help you a lot here.

It's hard to say for sure without knowing what files are in your theme but get_template_part( 'content', get_post_format() ); is essentially saying use the template named content-format.php, where format is one of image, video, gallery etc. One of a few things is happening:

Either your theme doesn't contain these templates at all, although you should still see posts in the fallback single.php format if that were the case. Still worth checking if they exist as no point using get_post_format()if they don't.

Or those templates are in a sub directory down form your category template in which case you'd need the format get_template_part( 'subfolder/content', get_post_format() );

Or your posts all have the default/standard format in which case get_post_format() will return false. If this is the case then you could remove get_post_format() and use just get_template_part( 'content' ); where all posts will use the default content template part. Alternatively you can assign a value to the false response:

get_header();
if ( have_posts() ) :
    while ( have_posts() ) : the_post();
    $format = get_post_format();
    if ( false === $format ) {
    $format = 'standard';
                            }
        get_template_part( 'content', $format );
    endwhile;
    get_template_part( 'includes/navigation', 'index' );
else:
    get_template_part( 'includes/no-results', 'index' );
endif;
get_footer();

Here you'd need to insure you added a content-standard.php alongside the other format template parts.

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.