在进行 WordPress 二次开发的时候,有时候需要知道 WordPress 后台当前页面的 Post type,下面的代码可以帮到参考:
function get_current_post_type() {
global $post, $typenow, $current_screen;
//we have a post so we can just get the post type from that
if ($post && $post->post_type) {
return $post->post_type;
} //check the global $typenow - set in admin.php
elseif ($typenow) {
return $typenow;
} //check the global $current_screen object - set in sceen.php
elseif ($current_screen && $current_screen->post_type) {
return $current_screen->post_type;
} //check the post_type querystring
elseif (isset($_REQUEST['post_type'])) {
return sanitize_key($_REQUEST['post_type']);
} //lastly check if post ID is in query string
elseif (isset($_REQUEST['post'])) {
return get_post_type($_REQUEST['post']);
}
//we do not know the post type!
return null;
}
拥有多年WordPress博客/企业建站开发经验,独树一帜的设计,提供最专业的网站设计方案;原创的主题标签语义化,增强网站优化效果。
增强用户体验、提高品牌形象给人留下深刻的印象,那就选择我们,我们的每一款主题都是独一无二的,都有自己的灵魂,每款主题都有各自的配色方案。
遵循现代网页设计的趋势,所有主题都提供完整的响应式布局,优化大桌面显示器以及对平板和智能手机的支持,从而提供一致性的用户体验。
长期及时地在线售后服务和免费升级更新,确保您的网站始终运行在最佳状态,24小时QQ在线的沟通方式免去您的后顾之忧,替您节省网站维护成本。
目前还没有评。