我试图用密码保护自定义页面模板中的内容,但是当我输入在后端分配的密码时,它不会进行身份验证,而只是在提交时重新加载页面。我知道下面的代码不太好,但请不要理会这一点-我只需要帮助密码验证正常工作。
它似乎也不会检查特定页面是否确实受密码保护,而是显示密码保护表单,无论该页面是公开的还是受密码保护的,所以我猜问题就在这里。
<div class="container">
<?php if (post_password_required()) { ?>
<div class="trips">
<div class="homewrap">
<?php
// get all the categories from the database
$args = array(\'orderby\' => \'id\', \'order\' => \'desc\');
$cats = get_categories($args);
$i = 0;
$n = 0;
// loop through the categries
foreach ($cats as $cat) {
// setup the cateogory ID
$cat_id = $cat->term_id;
// Make a header for the cateogry
$string = $cat->name;
$nstring = strtolower(str_replace(" ", "-", $string));
echo "<a href=\'/" .$nstring. "\'><div class=\'where\'><h2 class=\'place\'>".$cat->name."</h2></a>";
// create a custom wordpress query
query_posts("cat=$cat_id&posts_per_page=100");
// start the wordpress loop!
if (have_posts()) : while (have_posts()) : the_post(); ?>
<?php // create our link now that the post is setup
$i++;
if ($i >= 2) {
echo \'<div class="thing">\';
}
?>
<div class="location"><a href="<?php the_permalink();?>"><?php the_title(); ?></a></div>
<?php
$thumbnail = get_the_post_thumbnail();
$url = get_the_permalink();
$description = get_post_meta( get_the_ID(), \'description\', true );
echo \'<div class="pictures">\';
echo \'<div class="featured-thumb"><a href="\' .$url. \'">\' .$thumbnail. \'</a></div>\';
if (class_exists(\'Dynamic_Featured_Image\') ) {
global $dynamic_featured_image;
$featured_images = $dynamic_featured_image->get_featured_images( $postId );
$number = count($featured_images);
for ($i = 0; $i <= 1; $i++) {
echo \'<div class="featured-thumb"><a href="\' .$url. \'"><img src="\' .$featured_images[$i][\'full\']. \'"></a></div>\';
}
}
echo \'</div><!-- pictures -->\';
echo \'<div class="description">\' .$description. \'</div>\';
if ($i >= 2) {
echo \'</div><!-- .thing -->\';
}
?>
<?php endwhile; endif; // done our wordpress loop. Will start again for each category ?>
<?php } // done the foreach statement ?>
</div>
</div><!-- .container -->
</div><!-- .homewrap -->
</div><!-- .trips -->
<?php } else { echo get_the_password_form(); } ?>
<?php
get_footer();