我有两个单选按钮,可以启用/禁用wordpress主页中的特定类别帖子,
我还将这两个按钮添加到了single上。php,
这就是我所做的,
如果帖子属于“ABC”类别,且按钮处于启用状态,则显示以下消息:,
“请禁用按钮”(按钮就在此消息下方)
但当我选择禁用选项时,我会重定向到索引。php自动:它对分类页面非常有效,但对单个页面不起作用。php,为什么?
按钮代码,
<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>
这是类别内的代码。php,它工作正常,
<?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>";
}
?>
这是单曲里面的代码。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>
这是他们每个人身上的代码,
$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\';
}
该代码用于索引。php/archieve。php,但不适用于单个。php(选择“禁用/关闭”后,我将重定向到索引,php。