Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I have two radio buttons that enable/disable the particular category posts from my wordpress homepage,

I have also added these two buttons on single.php,

this is what I'v done,

If the post belong to category 'ABC' and button is enable then show the following messgae,

"PLEASE Disable the button" (the button is right under this message)

but when i choose disable option i am redirecting to the index.php automatically :S it works really fine for category pages but doesn't work for single.php , WHY?

buttons code,

<div id="filterbox">
    <form name="f1" method="POST" action="<?php echo $PHP_SELF;?>">
        <span>Family filter:</span>
        <ul>
        <li><input type="radio" name="r1" value="o" onClick="submit();" <?php echo (!$_SESSION['r1'] || $_SESSION['r1'] == "o") ? 'checked="checked"' : ''; ?> />On</li>
        <li><input type="radio" name="r1" value="p" onClick="submit();" <?php echo ($_SESSION['r1'] == "p") ? 'checked="checked"' : ''; ?> />Off</li>
        </ul>
    </form>
</div>

this is code inside category.php and it is working fine,

<?php 

    if ( in_category($category) && $_SESSION['r1'] == "o" ) { // See if the user is inside restricted category or if the Family filter is On (if one)
        echo "<div id='Naughtysms'>";
        echo "Please turn Off the 'Family filter' in order to read these SMS.<br /> these text messages are not suitable for user unders age 17";
        echo "</div>";
        echo "</div>";
    }
?>

This is the code inside single.php,

<?php

            $currentCat = get_the_category();  // Get the Array of Categories of current Post
            $filterCategory = $currentCat[0]->cat_ID; // store the First category in filterCategory
            if (($filterCategory == $category) && ($_SESSION['r1'] == "o" )){ // 
            ?>

please disable the button
<div id="filterbox">
    <form name="f1" method="POST" action="<?php echo $PHP_SELF;?>">
        <span>Family filter:</span>
        <ul>
        <li><input type="radio" name="r1" value="o" onClick="submit();" <?php echo (!$_SESSION['r1'] || $_SESSION['r1'] == "o") ? 'checked="checked"' : ''; ?> />On</li>
        <li><input type="radio" name="r1" value="p" onClick="submit();" <?php echo ($_SESSION['r1'] == "p") ? 'checked="checked"' : ''; ?> />Off</li>
        </ul>
    </form>
</div>

This is the code inside every one of them,

$choice = $_POST['r1'];
    $id = $category;
    if ($choice == 'o') // Family Filter !!! If 'ON'
        query_posts("cat=-.'$id'&".$query_string); // Remove Post from Category of particular ID
    else if (!$_SESSION['r1'] || $_SESSION['r1'] == "o") // If there is nothing in Session (opening page for the frst time) Remove the posts
        query_posts("cat=-.'$id'&".$query_string); 
    else {
        $_POST['r1'] = 'p';
    }

The code works for index.php / archieve.php but not working on single.php (i am redirecting onto index,php after choosing "disable/off".

share|improve this question
    
Do your posts have only one category, or might posts have more than one category? –  Chip Bennett Jan 25 '12 at 15:17
    
the post has just category –  Sufiyan Ghori Jan 25 '12 at 15:51

1 Answer 1

up vote 0 down vote accepted

It worked when i changed ,

echo $PHP_SELF;

with

 echo $_SERVER['PATH_INFO'];
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.