Support » Fixing WordPress » is_single() / is_singular not working instead of content-single.php

  • Hello,

    I have a question about is__single() / is_singular():

    I created some Custom Post Type (Portfolio) an loop this in page-portfolio.php. In the page-portfolio.php it gets the template-part <?php get_template_part( 'content', 'portfolio' ); ?>.

    In the content-portfolio.php I tried to code something like this:

    <?php if ( is_singular('portfolio') ) : ?>
    <!-- some stuff for displaying single CPT-post -->
    <?php else : ?>
    <!-- some stuff for displaying all CPT-posts (Portfolio)-->
    <?php endif; // is_singular() ?>

    Displaying all the posts is working, but not displaying the single post. WordPress uses the content-single.php to show the single portfolio post.

    In the Twentytwelve Template it works this way with post types (like posty type “image” etc.)… But in my own Template, the post type “image” wont work like this, when I use is_single()…

    Where is the mistake?

Viewing 1 replies (of 1 total)
  • I think i just solved the problem:

    in the single.php I coded in the loop:
    <?php get_template_part( 'content', get_post_type() ); ?> to get the custom post types Template content-portfolio.php.

    in the single-post.php I coded in the loop:
    <?php get_template_part( 'content', get_post_format() ); ?> to geh´t the custom post format Template like content-image.php.

    The decision between is_single() and !is_single() works.

    Is it possible to distinguish in this way? It works but I don’t know if it fits with the wordpress codex… Is it allowed to distinguish between “single-post” and “single” to distinguish between Custom post Format and Custom post Type and get different single Views?

Viewing 1 replies (of 1 total)
  • The topic ‘is_single() / is_singular not working instead of content-single.php’ is closed to new replies.