首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用登录保护wordpress自定义页面

使用登录保护wordpress自定义页面
EN

Stack Overflow用户
提问于 2016-08-27 17:22:24
回答 1查看 99关注 0票数 2

我是wordpress的新手,而且我刚刚开始使用自定义页面模板,如果不先登录,就不能让页面上的内容不可见。因此,我从复制基本模板开始:

代码语言:javascript
复制
<?php
/*
Template Name: Full width with no title template
*/
get_header();
?>

    <div class="clear"></div>
</header> <!-- / END HOME SECTION  -->
<?php zerif_after_header_trigger(); ?>
<div id="content" class="site-content">
    <div class="container">
        <div class="content-left-wrap col-md-12">
            <div id="primary" class="content-area">
                <main id="main" class="site-main" role="main">
                    <?php 
                        while ( have_posts() ) : 
                            the_post();
                            get_template_part( 'content', 'page-no-title' ); 
                            /* If comments are open or we have at least one comment, load up the comment template */
                            if ( comments_open() || '0' != get_comments_number() ) :
                                comments_template();
                            endif;
                        endwhile;
                    ?>
                </main><!-- #main -->
            </div><!-- #primary -->
        </div><!-- .content-left-wrap -->
    </div><!-- .container -->
</div><!-- .site-content -->
<?php
get_footer();
?>

现在,当我打开页面时,系统会提示我输入登录详细信息(我使用的是digimember插件)。但是,现在我想在页面上添加我的自定义内容,所以我在main元素内的php逻辑之后添加了一些HTML标记:

代码语言:javascript
复制
<main id="main" class="site-main" role="main">
                    <?php 
                        while ( have_posts() ) : 
                            the_post();
                            get_template_part( 'content', 'page-no-title' ); 
                            /* If comments are open or we have at least one comment, load up the comment template */
                            if ( comments_open() || '0' != get_comments_number() ) :
                                comments_template();
                            endif;
                        endwhile;
                    ?>
                 <h1>Should not be visible but it is</h1>
                </main><!-- #main -->

现在我仍然看到登录表单,但我也看到了字符串‘不应该可见,但它是’。如何限制此内容?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-08-27 17:33:23

您可以为访问者和渴望的用户设置此条件。

代码语言:javascript
复制
<?php
   if ( is_user_logged_in() ) {
      echo 'Your Code here !!!';
   } else {
      wp_login_form( $args );
   }
?>

有关更多详细信息,请访问此link

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/39179502

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档