- My site is comthainguyen.tk built with WordPress.
- You can see on left sidebar have Food Menu: Monday/TuesDay/... (this is Categories type).
- I want when users navigate to my Homepage URL (comthainguyen.tk), the category of current day will auto choose (click). I mean if today is Monday then Monday category will be chosen, and Tuesday then Tuesday category will be chosen, ....
如何根据WordPress中当前的每周日设置默认类别? [关闭]
- 写回答
- 好问题 0 提建议
- 追加酬金
- 关注问题
- 邀请回答
-
1条回答 默认 最新
- dongzhimeng2464 2018-08-04 04:56关注
I think you're thinking about this a tad wrong. You don't necessarily need/want to "auto-click" on the category. Just redirect to the appropriate category on based on the date.
Just make use the the current day with PHP's
date()
function, usewp_safe_redirect()
to redirect to the category using the day you just got, and wrap that all withis_front_page()
to make sure it's only fired if it's for the home page.Now all requests to the home page will get redirected to the current days' category instead. Something like this should get you started:
add_action( 'template_redirect', 'load_category_by_day' ); function load_category_by_day(){ if( is_front_page() ){ $current_day = strtolower( date('l') ); // 'monday', 'sunday', etc. wp_safe_redirect( site_url( "/category/$current_day/" ) ); } }
本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 无用评论 打赏 举报
悬赏问题
- ¥60 请查询全国几个煤炭大省近十年的煤炭铁路及公路的货物周转量
- ¥15 请帮我看看我这道c语言题到底漏了哪种情况吧!
- ¥66 如何制作支付宝扫码跳转到发红包界面
- ¥15 pnpm 下载element-plus
- ¥15 解决编写PyDracula时遇到的问题
- ¥15 有没有人能解决下这个问题吗,本人不会编程
- ¥15 plotBAPC画图出错
- ¥30 关于#opencv#的问题:使用大疆无人机拍摄水稻田间图像,拼接成tif图片,用什么方法可以识别并框选出水稻作物行
- ¥15 Python卡尔曼滤波融合
- ¥20 iOS绕地区网络检测