Check if wordpress archive page with all posts in concept

I have the following code which places text in a header based on what part of the site you are on:

<h1 class="heading">
    <?php 
        $posttype = get_post_type();
        switch ($posttype) {
             case "tekenplannen":
                echo "Tekenplannen - " . $details[ 'title' ]; 
                break;
            case "vacatures":
                //check if we are on the archive page
                if (is_archive()) {
                     echo "Open vacatures"; 
                } else {
                    echo "Vacature - " . $details[ 'title' ]; 
                }
                 break;
            case "object":
                if (is_archive()) {
                     echo "Toonzaal"; 
                } else {
                    echo $details[ 'title' ]; 
                }
                break;
            case "nieuws":
                //check if we are on the archive page
                if (is_archive()) {
                    echo "Nieuws"; 
                } else {
                    echo $details[ 'title' ]; 
                }
                break;
            default:
                 echo $details[ 'title' ]; 
                break;
            }
        ?>
</h1>

This code works perfectly fine as long as my archive page has a post published.
Imagine now that for example my “vacatures” custom post type has 4 published posts, my header title will contain “Vacatures” which is ok. Imagine now that I want to hide all my 4 posts, so they are placed in “draft” mode. If I then check my vacatures archive page again, the title will contain the text “Archives”.
Why is this not being caught by the is_archive() function? How do I catch this?

Read More

Thanks in advance

Related posts

1 comment

  1. @Dennis, if you are running in custom post type, for archive page, the conditional tag to make your content being displayed, you must use is_post_type_archive.

    is_post_type_archive( $post_types )
    

Comments are closed.