新闻中心

WordPress文章发布提示用户选择分类

作者 / 无忧主机 时间 2015-07-29 00:31:47

通过WordPress开源程序搭建的网站占全球网站的10%,而WordPress官方网站的每月独立访问用户数则达到3亿。这串美妙的数据可以看出WordPress广受全球站长厚爱,但是有一些操作上面的设计无忧主机小编认为非常不人性化,例如:站长在后台撰写文章,常常会忘记选择分类。在默认情况下,如果发布文章时没有选择分类,文章就会被自动归类到“默认文章分类目录”这种情况相信大家经常发生。今天无忧主机小编将给大家分享一下,当发布文章时未选择分类,就会显示一个提示信息。相信实现这个功能站长们都会拍掌交好。 实现WordPress文章发布提示用户选择分类功能操作步骤如下: (注意:以下代码默认只支持文章(post),见第5行的 if($post_type=='post') 就是判读) 1、FTP工具连接php空间 2、将下列代码插入当前使用WordPress主题文件目录内文件名:functions.php

add_action('admin_footer-post.php', 'choose_a_category_before_publish');
add_action('admin_footer-post-new.php', 'choose_a_category_before_publish');
function choose_a_category_before_publish(){
global $post_type;
if($post_type=='post'){
echo "<script>
jQuery(function($){
$('#publish, #save-post').click(function(e){
if($('#taxonomy-category input:checked').length==0){
alert('抱歉,发布文章前,请选择一个分类');
e.stopImmediatePropagation();
return false;
}else{
return true;
}
});
var publish_click_events = $('#publish').data('events').click;
if(publish_click_events){
if(publish_click_events.length>1){
publish_click_events.unshift(publish_click_events.pop());
}
}
if($('#save-post').data('events') != null){
var save_click_events = $('#save-post').data('events').click;
if(save_click_events){
if(save_click_events.length>1){
save_click_events.unshift(save_click_events.pop());
}
}
}
});
</script>";
}
}
无忧主机相关文章推荐阅读: WORDPRESS 3.5如何快速添加友情链接 WORDPRESS代码实现限制上传图片的尺寸大小 WORDPRESS程序如何快捷去除后台标题的-WORDPRESS字样

本文地址:https://www.51php.com/wordpress/19812.html

1
1
1
1
1
1
1

客户服务热线

0791-8623-3537

在线客服