2012-12-19 30 views
2

我已經創建了一個自定義的post-type'Clients',admin用戶可以創建新的客戶端,添加圖片和詳細信息發佈,然後密碼保護頁面,只有特定的客戶端才能訪問內容。密碼保護不適用於自定義帖子類型single-template.php? - WordPress的

爲了在前端顯示此類型的內容,我使用了single-clients.php模板。它完美地顯示內容,但密碼保護功能不會顯示錶單並隱藏內容,即使我處於不同的瀏覽器中,緩存清除/註銷Wordpress(以普通最終用戶的身份查看)。

我在這裏可能會做錯什麼?

<?php get_header(); ?> 

    <div class="container-client"> 

    <?php if (have_posts()) : while (have_posts()) : the_post(); ?> 

     Display all fields and content for post-type 

    <?php endif; ?> 

    <?php endwhile; else: ?> 

    <div class="alert-box error">Sorry, this page no longer exists :(&mdash; <a href="<?php bloginfo('url'); ?>/">Back to home</a></div> 

    <?php endif; ?> 

    </div> 

<?php get_footer(); ?> 

這大概是如何設置我的single-clients.php頁面。有什麼方法可以手動顯示密碼功能,以便在最終用戶訪問頁面時隱藏內容並顯示密碼錶單?

回答

1

我有完全相同這個問題,一些嘗試和閱讀食品後,我想出了這個解決方案:

<?php 
add_filter('single_template', function($single_template) { 
    global $post; 

    if ($post -> post_type == 'your-custom-post-type') { 
     if (!post_password_required()) { 
      $single_template = 'path-to-your/single-your-custom-post-type.php'; 
     } 
    } 

    return $single_template; 
}); 
?> 

這樣的頁面只呈現在自定義的單層視圖輸入密碼後,如果受密碼保護。

相關問題