开发者

Change the exsisting $_GET to increment by 1

开发者 https://www.devze.com 2023-02-16 17:30 出处:网络
How do I get my $_GET[\'ago\'] variable to increment by 1, currently it is set to what ever was previously selected however on my lastitem I want to increment it by 1

How do I get my $_GET['ago'] variable to increment by 1, currently it is set to what ever was previously selected however on my last

  • item I want to increment it by 1

    I want to change my URL only on 'Overnight' to increase by 1 each time its clicked if it is already ?ago=1 I want ?ago=2 as the href and if ?ago=2 increment to ?ago=3 etc

    I've try to do it with function filter_overnight but it's not working?

    <!-- below is the html list items -->
    
    
    <li id="menu-item-65831"><a href="?<?php echo $twd_helper->query_string(array('tod' => 'morning'), array('page'))  ?>">Morning</a></li>
    <li id="menu-item-65832"><a href="?<?php echo $twd_helper->query_string(array('tod' => 'afternoon'), array('page')) ?>">Afternoon</a></li>
    <li id="menu-item-65833"><a href="?<?php echo $twd_helper->query_string(array('tod' => 'evening'), array('page')) ?>">Evening</a></li>
    <li id="menu-item-65834"><a href="?<?php echo $twd_helper->query_string(array('tod' => 'overnight'), array('page'), array('ago')) ?>">Overnight</a></li>
    
    
    <!-- below is the included common php routines -->
    
    <?php
    
    function filter_where($where = '') {
    
        // posts in the last 30 days
        if (isset($_GET['ago'])) {
    
            if (is_page('future-tv-guide')) {
                $week = date('Y-m-d');
            } else {
                $week = date('Y-m-d', strtotime('-7 days'));
            }
            if (is_page('future-tv-guide')) {
                $previous = intval($_GET['ago']);
                $specific_date = date('Y-m-d', strtotime('+' . $previous . ' days'));
            } else {
                $previous = intval($_GET['ago']);
                $specific_date = date('Y-m-d', strtotime('-' . $previous . ' days'));
            }
            if ($_GET['ago'] == "week") {
                $where .= " AND post_date > '" . $week . "'";
            } else {
                $where .= " AND post_date>='$specific_date 00:00:00' AND post_date <= '$specific_date 23:59:59'";
            }
        }
    
        return $wher开发者_如何学编程e;
    
    }
    
    
    
    class TimeForTellyWPHelper {
        public function __construct($future=false) {
            $GLOBALS['twd_helper']=&$this;
        }   
        public function query_string($add, $remove=null) {
            $qs_data = array();
            parse_str($_SERVER['QUERY_STRING'], $qs_data);
            $qs_data = array_merge($qs_data, $add);
            if ($remove) {
                foreach($remove as $key) {
                    if (isset($qs_data[$key])) {
                        unset($qs_data[$key]);
                    }
                }
            }
            return http_build_query($qs_data);
        }
    
        public function filter_overnight () {
            if (isset($_GET['tod']) && $_GET['tod'] == 'overnight') {
                if ($_GET['ago'])
                {
                    $_GET['ago'] = (int)$_GET['ago'] + 1;
                }
                else
                {
                    $_GET['ago'] = 0;
                }
            }
    
        }   
    
        public function get_filter_summary() {
            if (isset($_GET['category']) && $_GET['category'] != 'all') {
                $category = $_GET['category'];
            }
            if (isset($_GET['channel']) && $_GET['channel'] != 'all') {
                $channel = $_GET['channel'];
            }
            if (isset($_GET['ago']) && $_GET['ago'] != 'week') {
                $ago = $_GET['ago'];
    
            }
    
            $summary = 'Results: ';
            if ($category || $ago || $channel) {
                if ($category) {
                    $summary .= get_term_by('slug', $category, 'programmecategories')->name . "";
                    } else {
                        $summary .= "All Categories";
                    }
    
                if ($ago) {
                    if (is_page('future-tv-guide')) {
                        if ($ago == "week") {
                            $summary .= " next week.";
                            } elseif ($ago == "1") {
    
                                $summary .= " / Tomorrow";
    
                            } else {
    
                            $thedate  = mktime(0, 0, 0, date('m'), date('d') + $ago, date('Y'));
    
                                //$summary .= " / in " . $ago . " days time";
                                $summary .= " / " . date( 'l jS', $thedate );
                        }
                    } else {
    
                        if ($ago == "week") {
    
                            $summary .= " last week.";
    
                            } elseif ($ago == "1") {
    
                                $summary .= " / Yesterday.";
    
                            } else {
    
                            $thedate  = mktime(0, 0, 0, date('m'), date('d') - $ago, date('Y'));
    
                                //$summary .= " / in " . $ago . " days time";
                                $summary .= " / " . date( 'l jS', $thedate );
                        }
                    }
                } else {
                    if (is_page('future-tv-guide')) {
                        $summary .= " / Today";
                    } else {
                        $summary .= " / Last week";
                    }
    
                }
    
                if ($channel) {
                    $summary .= " / " . get_term_by('slug', $channel, 'channelnames')->name . "";
                    } else {
                        $summary .= " / All Channels";
                    }
    
                return $summary;
            }
            return '';
        }
    
    
    
        public function get_posts($past) {
    
            $page = isset($_GET['page']) ? intval($_GET['page']) : 1;
            $posts_per_page = isset($_GET['per_page']) ? intval($_GET['per_page']) : 10;
    
            $query = array(
                'post_type' => 'programmes',
                'posts_per_page' => $posts_per_page,
                'paged' => $page,
                'suppress_filters' => false
            );
    
            if (!$past) {
                $query['orderby'] = 'date';
                $query['order'] = 'ASC';
            } else {
    
                if (isset($_GET['sort']) && $_GET['sort'] == 'recent') {
                    $query['orderby'] = 'date';
                    $query['order'] = 'DESC';
                } else {
                    $query['order'] = 'DESC';
                    $query['orderby'] = 'meta_value_num';
                    $query['meta_key']= 'popularityfig';
                }
            }
    
            $tax_query = array(
                'relation' => 'AND'
            );
            $meta_query = array();
            if ($past) {
                $query['post_status'] = 'publish';
                $meta_query[] = array(
                    'key' => 'linktovideocatchup',
                    'value' => "",
                    'compare' => 'NOT IN'
                );
            } else {
                $query['post_status'] = 'future';
            }
    
            if (isset($_GET['category'])) {
                if ($_GET['category'] != 'all')
                    $tax_query[] = array(
                        'taxonomy' => 'programmecategories',
                        'field' => 'slug',
                        'terms' => array( $_GET['category'] ),
                    );
            }
    
            if (isset($_GET['channel'])) {
                if ($_GET['channel'] != 'all')
                    $tax_query[] = array(
                        'taxonomy' => 'channelnames',
                        'field' => 'slug',
                        'terms' => array( $_GET['channel'] ),
                    );
            }
            if (isset($_GET['search'])) {
                $meta_query[] = array(
                    'key' => 'Programme Name',
                    'value' => $_GET['search'],
                    'compare' => 'LIKE'
                );
            }
            if (isset($_GET['tod'])) {
                    $meta_query[] = array(
                        'key' => 'Programme TOD',
                        'value' => $_GET['tod'],
                        'compare' => 'EXACT'
                    );
            }
            if (isset($_GET['letter'])) {
                $meta_query[] = array(
                    'key' => 'Programme Prefix',
                    'value' => $_GET['letter'],
                    'compare' => 'EXACT'
                );
            }
            if (sizeof($tax_query) > 1) {
                $query['tax_query'] = $tax_query;
            }
            if (sizeof($meta_query) > 0) {
                $query['meta_query'] = $meta_query;
            }
            add_filter( 'posts_where', 'filter_where' ); 
            return get_posts($query);
        }
    }
    ?>
    


    You're code's really long, please remove the unnecessary areas. As for your question, what you should be doing is this (only an example, you'll need to adapt it to your framework)

    PHP

    $ago = isset($_GET['ago']) ? (int) $_GET['ago'] : 0; //initally 0 on page load
    //do some stuff with ago
    $ago++; //ago is now +1 
    

    HTML

    <a href='/your-url/<?php echo $ago?'>Ago</a>
    

    So how it works is, initially you'll have $ago at 0 because it hasn't been set. But when the HTML is generated, the link will be pointing to your page with $ago + 1 since we incremented it at the bottom

  • 0

    精彩评论

    暂无评论...
    验证码 换一张
    取 消