• Resolved shadez

    (@shadez)


    Hi,
    As simple as this might seem, am not able to get it to work.

    What i need is get_template_part( 'content', get_post_format() ); to pick up content-image.php for image post-format.

    I have added theme support in functions file:
    add_theme_support( 'post-formats', array( 'image', 'video', 'gallery', 'aside', 'quote', 'link', 'status', 'audio', 'chat' ) );

    and this is my single.php loop:

    <?php if ( have_posts() ) {
    		while ( have_posts() ) : the_post(); // Start the loop
    			if ( is_single() ) {
    				echo 'single';
    				get_template_part( 'partials/content', 'single' );
    			} else {
    				echo 'post-format';
    				get_template_part( 'partials/content', get_post_format() );
    			}
    		endwhile; /* End the loop */
    	} else { ...

    I publish a new post and choose format as ‘image’ from RHS radio-button.

    But while viewing it, it goes to content-single.php instead of content-image.php code.

    Any ideas?

Viewing 2 replies - 1 through 2 (of 2 total)
  • review https://codex.www.ads-software.com/Function_Reference/is_single

    is_single() also is ‘true’ for a post of the ‘image’ post_format…

    possibly (untested, and dependent on if you also want to call the other content-{postformat}.php templates) try to rewrite the conditional statement to:

    if ( get_post_format() ) {
    				echo 'post-format';
    				get_template_part( 'partials/content', get_post_format() );
    			} else {
    				echo 'single';
    				get_template_part( 'partials/content',  'single' );
    			}
    Thread Starter shadez

    (@shadez)

    aah.. my understanding was wrong. i thought post-formats are other post types – ie different from single/standard post format.
    so i guess we can use conditional checks over get_post_format and has_post_format and fetch partials. thanks for the code.
    and thanks again Alchymyth for replying. ??

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘get_template_part for get_post_format() not working’ is closed to new replies.