0
  1. 我想对我的特定类别应用密码保护,在一个论坛中,我看到了这段代码。但是,它对我不起作用。
  2. 将此代码包含在我的主题的 function.php 中:

    global $post; if ( ! is_single() ) return false; // edit these $password = 'your password'; $protected_categories = array('category-slug-name'); // stop editing if ( in_category( $protected_categories, $post->ID ) && stripslashes( $_COOKIE['wp-postpass_' . COOKIEHASH] ) != $password ) { $post->post_content = get_the_password_form(); } } } ?>
  3. 关于此的任何想法。对我来说有点紧急。如果您有任何想法,请回复我的问题。提前致谢。

4

2 回答 2

0

我硬编码了我的类别页面以进行密码保护-

<?php 
global $wpdb;
//create a table named pass_protect_cat with password field in it.
$db_pass = $wpdb->get_results("SELECT password FROM pass_protect_cat",ARRAY_N); 
$db_pass1=array_shift( $db_pass );
$db_password=array_shift($db_pass1);
$cat_pass_entered=$_POST['pass'];
$displayform=true;
if ($_POST['submitted'] )
{
    if((strcmp($db_password,$cat_pass_entered)) == 0)
    {
        $displayform=false;
    ?>
        <?php while (have_posts()) : the_post(); ?>
            <p align="left" class="txt_small"><?php the_content().'<br/>'; ?></p>
        <?php endwhile; ?>
    <?php
    }
    else
    {
        echo '<b>'."Wrong Password".'</b>';
    }
}
if($displayform)
{

?>

<p align="left" class="txt_small" id="Message">These category posts are Password Protected.<br/>Enter the password to view the contents.</p>
                <form name="form1" id="form1" method="post" action="<?php password_protect_cat.php ?>" >
                    <label for="password">Password</label>
                    <input type="password" name="pass" id="pass" value="">
                    <input type="submit" name="submitted" id="submitted" value="Submit">
                </form>

<?php } ?>
于 2012-08-30T04:19:45.827 回答