PHP 单选按钮和 Submit()
我在我的 WordPress 中使用开/关单选按钮来隐藏特定类别的帖子,到目前为止我做得很好,
我的意思是当我将按钮设置为“开”时,ID 为 495 的类别中的帖子消失,当我如果关闭帖子回来,
请关闭,这就是我面临的问题,
我将按钮设置为“关闭”,以便类别 id 495 中的帖子消失,然后我单击“旧帖子”链接并转到上一页,但是当我选择了“打开”我自动跳回第 1 页:S
为什么会发生这种情况?为什么我点击“打开”时会自动跳回第一页? :S
这是代码,
这是标题代码,
<?php
session_start();
if (isset($_POST['r1'])){
$_SESSION['r1']=$_POST['r1'];
}
?>
这是我的两个单选按钮,
<li><input type="radio" name="r1" value="o" onClick="submit();" <?php echo ($_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>
这是index.php 中的代码,
<?php
if ($_POST['r1']=='o') // Family Filter !!! If 'ON'
query_posts('cat=-495'); // Remove Post from Category whose Id is 495
else {echo "";} // When off is selected
?>
index.php 中的代码有问题吗?
I am using On/off radio button inside my wordpress to hide post from a particular category and I've done well so far,
I mean when i set the button to 'On', posts from category whose id is 495 disappears and when i turn if off the posts comes back,
here is the problem i am facing,
I set the button to 'Off' so the posts from category id 495 disappears then i click on 'older posts' link and goes to previous pages but then when i chose 'On' i automatically jumped back to page number 1 :S
why is this happening ? Why am i automatically jumping back to 1st page when click 'On' ? :S
here is the code,
This is the header code,
<?php
session_start();
if (isset($_POST['r1'])){
$_SESSION['r1']=$_POST['r1'];
}
?>
these are my two radio buttons,
<li><input type="radio" name="r1" value="o" onClick="submit();" <?php echo ($_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>
and this is the code in index.php,
<?php
if ($_POST['r1']=='o') // Family Filter !!! If 'ON'
query_posts('cat=-495'); // Remove Post from Category whose Id is 495
else {echo "";} // When off is selected
?>
is there something wrong with the code inside index.php ??
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
一旦提交表单,参数
page
就会丢失。单击“较早的帖子”后,它会出现在查询字符串中。默认情况下,它等于 1。您已将其传递给
query_post
函数并使用类似query_posts('cat=-495&page='.$page);
的内容,其中
$page=(int)$_GET['page']; // 我不记得确切的参数名称了。
Once form is submitted parameter
page
is lost. It appears in query string after clicking on "Older posts". By default it equsls to 1.You have pass it to
query_post
function and use something like thisquery_posts('cat=-495&page='.$page);
where
$page=(int)$_GET['page']; // I don't remeber exactly parameter name.