密码保护获取帖子的页面模板?

时间:2014-10-09 14:59:15

标签: php wordpress passwords

我已经构建了一个模板,该模板可以从一个类别中获取帖子并添加了这个模板,因为我希望它受密码保护。它似乎不起作用,我不知道为什么。

有人能帮助我吗?

<?php
if ( ! post_password_required( $post ) ) {

$temp = $wp_query; $wp_query= null;
$wp_query = new WP_Query(); $wp_query->query('cat=495' . '&paged='.$paged);
while ($wp_query->have_posts()) : $wp_query->the_post(); ?>

<div <?php post_class() ?>>
<h3 id="post-<?php the_ID(); ?>"><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent          Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></h3>

<div class="entry">
 <?php the_content() ?>
 </div>

 <br>

 </div>

  <?php endwhile; ?>

 }else{
// we will show password form here
echo get_the_password_form();
 }

 ?>

2 个答案:

答案 0 :(得分:0)

`<?php
/*
Template Name: Privileged Customers Template
*/

get_header();
?>
<table width="1000" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td><img src="../../../images/blank_middle/blank_middle_01.jpg" width="57" height="20"></td>
<td><img src="../../../images/blank_middle/blank_middle_02.jpg" width="886" height="20"></td>
<td><img src="../../../images/blank_middle/blank_middle_03.jpg" width="57" height="20"></td>
 </tr>
 <tr>
<td background="../../../images/blank_middle/blank_middle_04.jpg"><img src="../../../images/spacer.gif" width="57" height="416" /></td>
<td valign="top" background="../../../images/blank_middle/blank_middle_05.jpg"><table width="886"   border="0" cellspacing="0" cellpadding="0">
    <tr>
      <td><img src="../../../images/spacer.gif" width="30" height="1" /></td>
      <td><img src="../../../images/spacer.gif" width="826" height="1" /></td>
      <td><img src="../../../images/spacer.gif" width="30" height="1" /></td>
    </tr>
    <tr>
      <td><img src="../../../images/spacer.gif" width="30" height="10" /></td>
      <td align="left">
      <div id="content" class="narrowcolumn" role="main">
 <h2><?php the_title();?></h2>
 <?php do_action('posts_logout_link'); ?>
 <?php
 if ( ! post_password_required( $post ) ) {

 $temp = $wp_query; $wp_query= null;
 $wp_query = new WP_Query(); $wp_query->query('cat=495' . '&paged='.$paged);
 while ($wp_query->have_posts()) : $wp_query->the_post(); ?>

 <div <?php post_class() ?>>
<h3 id="post-<?php the_ID(); ?>"><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent               Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></h3>

<div class="entry">
<?php the_content() ?>
 </div>

 <br>

 </div>

<?php endwhile; ?>

}else{
// we will show password form here
echo get_the_password_form();
}

?>



  </div>
      </td>
      <td><img src="../../../images/spacer.gif" width="30" height="10" /></td>
    </tr>
  </table></td>
<td background="../../../images/blank_middle/blank_middle_06.jpg"><img    src="../../../images/spacer.gif" width="57" height="416" /></td>

          `

答案 1 :(得分:0)

在您发布的代码的第46-53行,您有:

<?php endwhile; ?>

}else{
// we will show password form here
echo get_the_password_form();
}

?>
第46行你在同一行打开和关闭PHP,然后尝试运行更多PHP(第48行)。由于您关闭了PHP并且没有再次打开它,因此从第48行开始的PHP将呈现为HTML ...因此,您的if / else语句永远不会被正确关闭...因此Parse error: syntax error, unexpected $end错误。< / p>

更改第46行:

<?php endwhile; ?>

为:

<?php endwhile;