有时候,我们需要连续发布同一个分类下的文章,每篇文章都要重新选择分类非常麻烦。下面,我们就用程序来搞定这个问题。
add_action('publish_post', 'save_fl' );
add_action('admin_footer-post.php', 'choose_a_category_before_publish');
add_action('admin_footer-post-new.php', 'choose_a_category_before_publish');
function save_fl($post_id)
{
if ( wp_is_post_revision( $post_id ) )
return;
global $current_user;
update_option( 'default_fl_' . $current_user->ID , json_encode($_POST['post_category']) );
get_option('default_fl_' . $current_user->ID);
}
function choose_a_category_before_publish(){
global $post_type;
global $current_user;
$post_categorys = json_decode(get_option('default_fl_' . $current_user->ID), TRUE);
if($post_type=='post'){
?>
<script>
jQuery(function($){
<?
if(count($post_categorys) > 0)
foreach($post_categorys as $post_category)
{?>
$("#in-category-<? echo $post_category; ?>").attr("checked","checked");
<?}
?>
});
</script><?
}
}
作者:黄聪
出处:http://www.cnblogs.com/huangcong/
本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。
出处:http://www.cnblogs.com/huangcong/
本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。

浙公网安备 33010602011771号