如何让我的$ _GET ['previous']变量增加1,目前它被设置为之前选择的值但是在我上一次
我想仅在'隔夜'更改我的网址,每次点击时都会增加1 如果它已经?之前= 1我想要?之前= 2作为href,如果?之前= 2增量到?前= 3等
我尝试使用函数filter_overnight进行操作,但它不起作用?
<!-- 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 $where;
}
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);
}
}
?>
答案 0 :(得分:1)
你的代码很长,请删除不必要的区域。至于你的问题,你应该做的是这个(只是一个例子,你需要让它适应你的框架)
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>
所以它是如何工作的,最初你将$ago
置于0,因为它尚未设置。但是当生成HTML时,链接将指向您的页面$ $ 1 +,因为我们在底部递增它