php WordPress从URL获取年份和月份
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了php WordPress从URL获取年份和月份相关的知识,希望对你有一定的参考价值。
<?php // ignore this line
// $year and $monthnum are the variables to be used.
$year = false;
$monthnum = false;
$matches = array();
$matches2 = array();
$url = $_SERVER['REQUEST_URI'];
preg_match("/CPT_SLUG_GOES_HERE\/([0-9]{4})\/([0-9]{1,2})\/?$/", $url, $matches);
preg_match("/CPT_SLUG_GOES_HERE\/([0-9]{4})\/([0-9]{1,2})\/page\/?([0-9]{1,})\/?$/", $url, $matches2);
if ( ! empty( $matches ) ) {
$year = $matches[2] ? $matches[1] : false;
$monthnum = $matches[2] ? $matches[2] : false;
} elseif ( ! empty( $matches2 ) ) {
$year = $matches2[2] ? $matches2[1] : false;
$monthnum = $matches2[2] ? $matches2[2] : false;
}
以上是关于php WordPress从URL获取年份和月份的主要内容,如果未能解决你的问题,请参考以下文章