admin管理员组文章数量:1130349
I want to implement a page, let's say /today-deals that will show all posts under today category, like if we were navigating to /category/deals-for-october-31-2018 but without changing the URL.
I want to implement a page, let's say /today-deals that will show all posts under today category, like if we were navigating to /category/deals-for-october-31-2018 but without changing the URL.
1 Answer
Reset to default 0I achieved it using template_include hook:
add_filter(
'template_include',
function ($template) {
if (is_page('today-deals')) {
global $wp_query;
$wp_query = new WP_Query( array( 'category_name' => date('Ymd') ) );
$template = 'category.php';
}
return $template;
}
);
I want to implement a page, let's say /today-deals that will show all posts under today category, like if we were navigating to /category/deals-for-october-31-2018 but without changing the URL.
I want to implement a page, let's say /today-deals that will show all posts under today category, like if we were navigating to /category/deals-for-october-31-2018 but without changing the URL.
1 Answer
Reset to default 0I achieved it using template_include hook:
add_filter(
'template_include',
function ($template) {
if (is_page('today-deals')) {
global $wp_query;
$wp_query = new WP_Query( array( 'category_name' => date('Ymd') ) );
$template = 'category.php';
}
return $template;
}
);
本文标签: Internal redirect from page to category
版权声明:本文标题:Internal redirect from page to category 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:https://it.en369.cn/questions/1749216839a2334298.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。


发表评论