Пример #1
0
    function pages()
    {
        global $p;
        $url = explode('?', $p->uri);
        ?>
        <div class="pagination-links">
<?php 
        for ($i = 1; $i <= $this->num_pages; $i++) {
            if (!$_GET['page' . $this->i] || $_GET['page' . $this->i] == $i) {
                $selected = 'selected';
            } else {
                $selected = '';
            }
            $qs = qs_remove('page' . $this->i);
            if ($i != 1) {
                $qs .= '&page' . $this->i . '=' . $i;
            }
            ?>
            <a href="<?php 
            echo $url[0];
            if ($qs) {
                echo '?' . $qs;
            }
            ?>
" class="pagination-link <?php 
            echo $selected;
            ?>
"><?php 
            echo $i;
            ?>
</a>
<?php 
        }
        ?>
        </div>
<?php 
    }
/**
 * remove one or more variables from a querystring
 * <br><br>Example:
 * <code>
 * <a href="?page=1&<?=qs_remove('page',$_SERVER['QUERY_STRING'])?>">Page 1</a>
 * // discard the current $_GET['page'], but retain any additional $_GET values
 * <a href="?<?=qs_remove(array('a','b'),'a=1&b=2&c=3')?>">Link</a>
 * // result: href="index.php?c=3"
 * </code>
 * @param string/array $name name(s) of variables to be removed from specified querystring
 * @param string $qs querystring possibly containing specific variables to be removed
 * @return string returns a querystring less the variables specified to be removed
 */
function qs_remove($name, $qs = null)
{
    //return a querystring $qs with the get-value $x removed
    // $x may be an array
    // i.e. qs_remove("fname",$_SERVER['QUERY_STRING'])
    if (!$qs) {
        $qs = $_SERVER['QUERY_STRING'];
    }
    $x = $name;
    if (is_array($x)) {
        while (list($var, $val) = each($x)) {
            $qs = qs_remove($val, $qs);
        }
        //while
        return $qs;
    }
    //if
    parse_str($qs, $parts);
    unset($parts[$name]);
    return http_build_query($parts);
}