我尝试对自定义页面进行密码保护,以便在显示任何内容之前,用户必须输入密码。更具体地说,在我下面的代码中,content div容器中的任何内容都应该受到密码保护:
<?php
/*
Template Name: custom_page
*/
?>
<?php get_header(); ?>
<div id="content">
  <div id="main">
<ul class="post">
        <li><b>LATEST POSTS</li>
 <?php
    $args = array(\'category\' => 5, \'post_type\' =>  \'post\');
    $postslist = get_posts( $args );    
    foreach ($postslist as $post) :  setup_postdata($post); 
    ?> 
    <li id="post-<?php the_ID(); ?>">
      <h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2> 
    <?php the_excerpt(); ?>
    </li>
    <?php endforeach; ?>
</ul> 
</div><!-- end content -->
<?php get_sidebar(); ?>
<?php get_footer(); ?>
 我尝试使用这里介绍的方法
Password protecting a page
但无法使其工作,因为我不知道如何将php代码包装到建议的解决方案中。