2016-08-27 6 views
2

私はWordPressを初めて使用しています。カスタムページテンプレートを作成し始めたばかりで、ページに表示されないようにすることはできません。基本的なテンプレートのコピーを開始しまし:私は、ページを開いたときにログインしてwordpressのカスタムページを保護する

<?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プラグインを使用しています)ログイン情報を入力するように求められます。しかし、今私は、ページ上の私のカスタムコンテンツを追加したいので、私はメインの要素内のPHPロジックの後にいくつかのHTMLマークアップを追加しました:「

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

今、私はまだログインフォームを参照してください、私はまた、文字列が表示されます見えませんが、それはです。どのようにしてこのコンテンツを制限できますか?

答えて

1

この条件は、訪問ユーザーと憧れのユーザーに設定できます。

<?php 
    if (is_user_logged_in()) { 
     echo 'Your Code here !!!'; 
    } else { 
     wp_login_form($args); 
    } 
?> 

詳しくは、linkをご覧ください。

+1

ええ、digimemberに付属のデフォルトのログインフォームを使用したいと思います。このフォームはコードなしで表示されますが、else節にハードコードを含めることはできません。 – Zed

+0

<?php if (is_user_logged_in()){ echo 'ようこそ、登録ユーザー!'; } else { wp_login_form($ args); } ?> –

+0

このURLにアクセスすると、「http://justintadlock.com/archives/2011/08/30/adding-a-login-form-to-a-page」と表示されます。 –