您可以从$wp_query
对象:
if( is_date() ){
if( isset( $wp_query->query_vars[\'year\'] ) ){
echo \'queried year is \' . $wp_query->query_vars[\'year\'];
}
if( isset( $wp_query->query_vars[\'monthnum\'] ) ){
echo \'queried month is \' . $wp_query->query_vars[\'monthnum\'];
}
if( isset( $wp_query->query_vars[\'day\'] ) ){
echo \'queried day is \' . $wp_query->query_vars[\'day\'];
}
}
或者只是通过
get_query_var()
:
echo get_query_var( \'year\' );
这回答了你的问题吗?
EDIT
您可以通过检查permalink结构选项的存在来检查站点是否使用了相当长的permalinks。在这种情况下,您可以获取并解析
m
查询变量而不是
year
/
monthnum
/
day
:
if( get_option(\'permalink_structure\') ){
// using pretty permalinks
} else {
// not using pretty permalinks
// note that month or day may be empty
// test for their existence before trying to use!
$year = substr( get_query_var( \'m\' ), 0, 4);
$month = substr( get_query_var( \'m\' ), 4, 2);
$day = substr( get_query_var( \'m\' ), 6, 2);
}