黄聪

论SEO对人类的重要性,请看我的博客:hcsem.com

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::

有时候,我们需要连续发布同一个分类下的文章,每篇文章都要重新选择分类非常麻烦。下面,我们就用程序来搞定这个问题。

 

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><?
    }
}

 

posted on 2015-03-19 09:46  黄聪  阅读(535)  评论(0编辑  收藏  举报