5ucms论坛
标题:
向快速编辑区域添加修改排序的功能
[打印本页]
作者:
admin
时间:
2021-6-16 14:59
标题:
向快速编辑区域添加修改排序的功能
//快速编辑项增加内容
add_action('quick_edit_custom_box', 'io_add_quick_edit', 10, 2);
function io_add_quick_edit($column_name, $post_type) {
if ($column_name == 'ranks') {//值与前方代码对应
//请注意:<fieldset>类可以是:
//inline-edit-col-left,inline-edit-col-center,inline-edit-col-right
//所有列均为float:left,
//因此,如果要在左列,请使用clear:both元素
?>
<fieldset class="inline-edit-col-right">
<div class="inline-edit-col">
<label class="alignleft">
<span class="title">排序</span>
<span class="input-text-wrap"><input type="number" name="rank" class="ptitle" value="" /></span>
</label>
<em class="alignleft inline-edit-or"> -999~999 越大越靠前</em>
</div>
</fieldset>
<?
}
}
//快速编辑处的值填入默认值
add_action('admin_footer', 'ashuwp_quick_edit_javascript');
function ashuwp_quick_edit_javascript() {
global $current_screen;
if (($current_screen->id != 'edit-post') || ($current_screen->post_type != 'post')) return;
//if($current_screen->id == 'edit-sites'){
//修改下方 js 代码中的 ordinal 为前方代码对应的值
?>
<script type='text/javascript'>
jQuery(function($){
var wp_inline_edit_function = inlineEditPost.edit;
inlineEditPost.edit = function( post_id ) {
wp_inline_edit_function.apply( this, arguments );
var id = 0;
if ( typeof( post_id ) == 'object' ) {
id = parseInt( this.getId( post_id ) );
}
if ( id > 0 ) {
var specific_post_edit_row = $( '#edit-' + id ),
specific_post_row = $( '#post-' + id ),
product_price = $( '.column-ranks', specific_post_row ).text();
$('input[name=\"rank\"]', specific_post_edit_row ).val( product_price );
}
}
});
</script>
<?
//}
}
//保存这个字段
add_action('save_post', 'io_save_quick_edit_data');
function io_save_quick_edit_data($post_id) {
//如果是自动保存日志,并非我们所提交数据,那就不处理
if ( defined('DOING_AUTOSAVE') && DOING_AUTOSAVE )
return $post_id;
// 验证权限,'sites' 为文章类型,默认为 'post' ,这里为我自定义的文章类型'sites'
if ( 'sites' == $_POST['post_type'] ) {
if ( !current_user_can( 'edit_page', $post_id ) )
return $post_id;
} else {
if ( !current_user_can( 'edit_post', $post_id ) )
return $post_id;
}
$post = get_post($post_id);
// 'ordinal' 与前方代码对应
if (isset($_POST['rank']) && ($post->post_type != 'rank')) {
$left_menu_id = esc_attr($_POST['rank']);
if ($left_menu_id)
update_post_meta( $post_id, 'rank', $left_menu_id);// ‘_sites_order’为自定义字段
}
}
复制代码
欢迎光临 5ucms论坛 (http://bbs.5ucms.com/)
Powered by Discuz! X3.2