输入密码后隐藏表单。使用WordPress和(!post_password_required())

时间:2014-05-14 23:36:56

标签: php wordpress

我有一个受密码保护的WordPress页面。它目前正在使用自定义字段来显示内容,所以我不得不使用(!post_password_required())来隐藏我想要的区域。

代码如下:

<?php if (!post_password_required()) { ?>
<?php the_content(); ?>

<h1>Application Received</h1>

<?php $loop = new WP_Query(array('post_type' => 'applications', 'posts_per_page' => 100)); ?>
<?php while ($loop->have_posts()) : $loop->the_post(); ?>

   <?php the_field('last-name'); ?> <br />
   <a href="mailto:<?php the_field("email"); ?>"><?php the_field("email"); ?></a> <br />
   <?php the_field('organisation'); ?>

<?php endwhile; ?>

<?php } else; { ?>

   <div class="login">
     <h1>SAC Login</h1>
     <?php echo custom_password_form(); ?>
   </div>
</main>
<?php } ?>

所以这一切都按照我的预期工作,但问题是一旦你输入密码并且隐藏的内容变得可见,密码表单就会停留在页面上(在现在可见的内容下面)。我认为一旦内容出现就会消失?

有关我如何解决这个问题的任何想法?任何投入都将非常感激。

1 个答案:

答案 0 :(得分:3)

<?php 
     if (!post_password_required())
     {
          the_content();
          $loop = new WP_Query(array('post_type' => 'applications', 'posts_per_page' => 100));
          while ($loop->have_posts()) : 
              $loop->the_post();
              the_field('last-name');
              the_field("email");
              the_field("email");
              the_field('organisation');
          endwhile;
      } 
      else; 
      {
          echo custom_password_form();
      }
?>

这是您的PHP等效页面,因为您可以看到其他内容有分号导致问题。