简体   繁体   English

PHP单选按钮和Submit()

[英]PHP radio buttons and submit()

I am using On/off radio button inside my wordpress to hide post from a particular category and I've done well so far, 我正在使用Wordpress中的“开/关”单选按钮来隐藏特定类别的帖子,到目前为止,我做得很好,

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, 我的意思是,当我将按钮设置为“开”时,ID为495的类别中的帖子消失了,而如果关闭则关闭时又回来了,

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 我将按钮设置为“关”,因此类别ID 495中的帖子消失了,然后单击“旧帖子”链接并转到上一页,但是当我选择“开”时,我会自动跳回到第1页:S

why is this happening ? 为什么会这样呢? Why am i automatically jumping back to 1st page when click 'On' ? 为什么单击“开”时我会自动跳回到第一页? :S :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, 这是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 ?? index.php内的代码有什么问题吗?

Once form is submitted parameter page is lost. 表单提交后,参数page将丢失。 It appears in query string after clicking on "Older posts". 单击“较早的帖子”后,它显示在查询字符串中。 By default it equsls to 1. 缺省情况下,等于1。

You have pass it to query_post function and use something like this 您已将其传递给query_post函数,并使用类似这样的内容

query_posts('cat=-495&page='.$page);

where 哪里

$page=(int)$_GET['page']; // I don't remeber exactly parameter name.

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM