簡體   English   中英

檢查wordpress存檔頁面中是否包含所有帖子

[英]Check if wordpress archive page with all posts in concept

我有以下代碼,該代碼根據您所在網站的哪個部分將文本放在標題中:

<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>

只要我的存檔頁面上有一篇帖子,此代碼就可以正常工作。 現在想象一下,例如,我的“職位”自定義帖子類型有4個發布的帖子,我的標題將包含“職位”,這是可以的。 現在想象一下,我想隱藏我所有的4個帖子,因此它們處於“草稿”模式。 如果然后再次檢查我的職位檔案頁面,標題將包含文本“ Archives”。 為什么這不能被is_archive()函數捕獲? 我該如何捕捉?

提前致謝

@Dennis ,如果您以自定義帖子類型運行,則對於存檔頁面(要顯示內容的條件標記),必須使用is_post_type_archive

is_post_type_archive( $post_types )

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM