【发布时间】:2014-06-17 20:30:24
【问题描述】:
我有一个在 WordPress 中创建的日历。顶部有下个月和上个月的链接。他们可以顺利浏览当前年份,但是当年份更改为下一年或上一年时,我会收到 404 错误。
每个月的链接如下所示(例如 2014 年 1 月):mysiteurl.com/calendar-grid/?year=2014&month=1
我尝试在?year 之前输入正确的网址,无论是否带有/,但这不起作用。
这就是我获取数据的方式:
if($_GET['month'] == ''){
$currmonth = date('n');
$thisyear = date('Y');
}
else {
$currmonth = $_GET['month'];
$thisyear = $_GET['year'];
}
$thismonth = paddNum($currmonth);
$firstday = $thisyear.$thismonth.'01';
$lastday = date('Ymt', strtotime($firstday));
$numdays = $lastday - $firstday + 1;
$firstDOW = date('N', strtotime($thisyear.'/'.$thismonth.'/01')) + 1;
if($firstDOW == 8) $firstDOW = 1;
$nextmonth = $thismonth + 1;
$prevmonth = $thismonth - 1;
$nextyear = $thisyear;
$prevyear = $thisyear;
if($nextmonth == 13){
$nextmonth = 1;
$nextyear = $thisyear + 1;
}
elseif($prevmonth == 0){
$prevmonth = 12;
$prevyear = $thisyear - 1;
}
$args = array(
'post_type' => 'event',
'meta_query' => array(
array(
'key' => 'event_date',
'compare' => 'BETWEEN',
'value' => array($firstday, $lastday)
)
),
'posts_per_page' => -1
);
$posts = get_posts($args);
这就是链接的创建方式:
<div class="month-head-text">
<a class="month-prev" href="<?php echo get_home_url(); ?>/calendar-grid?year=<?php echo $prevyear; ?>&month=<?php echo $prevmonth; ?>">
<img src="<?php echo get_template_directory_uri(); ?>/images/prev-month.png" />
</a>
<div class="month-name"><?php echo translateMonth($thismonth); ?></div>
<a class="month-next" href="<?php echo get_home_url(); ?>/calendar-grid?year=<?php echo $nextyear; ?>&month=<?php echo $nextmonth; ?>">
<img src="<?php echo get_template_directory_uri(); ?>/images/next-month.png" />
</a>
<a class="close-cal" href="<?php echo get_home_url(); ?>/calendar"><img src="<?php echo get_template_directory_uri(); ?>/images/close.png" /></a>
</div>
这是 2014 年 12 月的链接:http://houseof.mspaceap.com/calendar-grid/?year=2014&month=12
【问题讨论】: