我的问题很简单。我创建了一个新的自定义页面模板,名为page-printable.php
. 然后,我用slug创建了一个页面printable
. 如果我使用localhost/printable
或localhost/index.php?pagename=printable
, 它显示我的自定义页面,没有错误。但是,我的自定义页面使用$_GET
内部。但是如果我用localhost/printable?p_year=2018
甚至没有漂亮的url(localhost/index.php?pagename=printable&p_year=2018
), 而不是返回正确的自定义页面,查询位于$_GET
, 它返回一个404 not found。
这是我的密码page-printable.php
:
<html <?php language_attributes() ?>>
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width,initial-scale=1,user-scalable=no">
<title>Calendário</title>
<link href="https://fonts.googleapis.com/css?family=Mukta+Vaani:400,600,700|Roboto+Mono:500,700"
rel="stylesheet">
<link rel="stylesheet" href="http://localhost/frontend/dist/assets/css/main.css" type="text/css">
</head>
<body>
<?php echo $query ?>
<div class="una-printable">
<?php
if (!empty($_GET[\'p_year\'])) {
$query[\'year\'] = $_GET[\'p_year\'];
}
if (!empty($_GET[\'p_month\'])) {
$query[\'month\'] = $_GET[\'p_month\'];
}
$query = !empty($query) ? "?" . http_build_query($query) : \'\';
$events = json_decode(file_get_contents("http://dev.unasp.edu.br/wp-json/custom_api/v1/printable" . $query), true);
$month_name = [\'Janeiro\', \'Fevereiro\', \'Março\', \'Abril\', \'Maio\', \'Junho\', \'Julho\', \'Agosto\', \'Setembro\', \'Outubro\', \'Novembro\', \'Dezembro\'];
ksort($events);
foreach ($events as &$months) {
ksort($months);
foreach ($months as &$days) {
ksort($days);
}
}
foreach ($events as $year => $months) : ?>
<hr />
<div class="year">
<h1><?php echo $year ?></h1>
</div>
<hr />
<?php foreach ($months as $month => $days) : ?>
<h2><?php echo $month_name[$month - 1] ?></h2>
<table>
<tr>
<th>Data</th>
<th>Evento</th>
<th>Unidades</th>
</tr>
<?php foreach ($days as $day => $events) : ?>
<?php foreach ($events as $event) :
$date = date(\'Y-m-d\', strtotime("{$year}-{$month}-{$day}")) ?>
<tr>
<td>
<?php echo date(\'d/m\', strtotime($date));
if ($event[\'end\'] !== $date) {
echo " – " . date(\'d/m\', strtotime($event[\'end\']));
}
?>
</td>
<td><?php echo $event[\'name\'] ?></td>
<td>
<ul>
<?php foreach ($event[\'unities\'] as $unity) : ?>
<li><?php echo $unity ?></li>
<?php endforeach ?>
</ul>
</td>
</tr>
<?php endforeach;
endforeach; ?>
</table>
<?php endforeach;
endforeach ?>
</div>
<script>
const fn = () => window.print()
if (document.attachEvent ? document.readyState === "complete" : document.readyState !== "loading"){
fn();
} else {
document.addEventListener(\'DOMContentLoaded\', fn);
}
</script>
</body>
</html>
我该怎么办?
根据建议Aadil P., 我试着用query_vars
筛选以添加我的查询,如下代码所示:
add_filter(\'query_vars\', function ($qv) {
$qv[] = \'p_year\';
$qv[] = \'p_month\';
return $qv;
});
我没有忘记刷新Permalink页面中的重写。不幸的是,这并没有产生任何影响。
提前谢谢。