WordPress文章ID连续问题

时间:2011年05月06日作者:西风查看次数:2,939次评论次数:16

不知道有多少人说过WordPress文章ID连续的问题,但是解决的都不是很彻底,我现在自身用的插件是Super Switch(中文版本叫超级开关)高山仰止插件主页 WordPress插件官方页面,效果有时候还是不太理想。看下面的方法吧!
Super Switch
安装Super Switch这个插件,将“保存修订版本”和“自动保存”设为禁止。

WordPress3.1版本修改方法

然后找到”/wp-admin/includes/post.php”文件,搜索“$create_in_db

if ( $create_in_db ) {
	    // Cleanup old auto-drafts more than 7 days old
	    $old_posts = $wpdb->get_col( "SELECT ID FROM $wpdb->posts WHERE post_status = 'auto-draft' AND DATE_SUB( NOW(), INTERVAL 7 DAY ) > post_date" );
	    foreach ( (array) $old_posts as $delete )
	        wp_delete_post( $delete, true ); // Force delete
	    $post_id = wp_insert_post( array( 'post_title' => __( 'Auto Draft' ), 'post_type' => $post_type, 'post_status' => 'auto-draft' ) );
	    $post = get_post( $post_id );
	    if ( current_theme_supports( 'post-formats' ) && post_type_supports( $post->post_type, 'post-formats' ) && get_option( 'default_post_format' ) )
	        set_post_format( $post, get_option( 'default_post_format' ) );
	} else {
	    $post->ID = 0;
	    $post->post_author = '';
	    $post->post_date = '';
	    $post->post_date_gmt = '';
	    $post->post_password = '';
	    $post->post_type = $post_type;
	    $post->post_status = 'draft';
	    $post->to_ping = '';
	    $post->pinged = '';
	    $post->comment_status = get_option( 'default_comment_status' );
	    $post->ping_status = get_option( 'default_ping_status' );
	    $post->post_pingback = get_option( 'default_pingback_flag' );
	    $post->post_category = get_option( 'default_category' );
	    $post->page_template = 'default';
	    $post->post_parent = 0;
	    $post->menu_order = 0;
	}

将上面的代码替换成

if ( $create_in_db ) {
	    global $current_user;
	    $post = $wpdb->get_row( "SELECT * FROM $wpdb->posts WHERE post_status = 'auto-draft' AND post_type = '$post_type' AND post_author = $current_user->ID ORDER BY ID ASC LIMIT 1" );
	    if ( !$post ) {
	        $post_id = wp_insert_post( array( 'post_title' => __( 'Auto Draft' ), 'post_type' => $post_type, 'post_status' => 'auto-draft' ) );
	        $post = get_post( $post_id );
	    }
	    /* End */
	    // Below is added in 3.1
	    if ( current_theme_supports( 'post-formats' ) && post_type_supports( $post->post_type, 'post-formats' ) && get_option( 'default_post_format' ) )
	        set_post_format( $post, get_option( 'default_post_format' ) );
	}

WordPress3.0版本修改方法

首先打开根目录下的wp-config.php文件,在 $table_prefix = ‘wp_’; 前面添加代码

	define ('WP_POST_REVISIONS', false);
	define ('AUTOSAVE_INTERVAL', false);

然后找到并打开wp-admin/post-new.php(第46行)和wp-admin/post.php(第177行)这两个文件,将其 wp_enqueue_script(‘autosave’); 注释或删除掉。

// wp_enqueue_script('autosave');

最后找到并打开wp-admin/includes/post.php文件,找到if ( $create_in_db ),在前面添加一行$create_in_db = false;,变成:

	$create_in_db = false;
	if ( $create_in_db ) {

通过上述两种方法,可以有效解决这个问题,但是如果你图片不是使用外链直接上传的话,ID还是要占用的!

文章是否有趣?那就点击订阅吧!

声明: 本文采用 BY-NC-SA 协议进行授权 | 西风
转载请注明转自《WordPress文章ID连续问题


16条评论
  1. 静脉曲张Firefox 8.0.1Windows XP 留言于:2011年12月13日 13:23 回复

    什么东东,我来学习一下

  2. 论道Google Chrome 14.0.835.202Windows 7 留言于:2011年12月13日 09:17 回复

    使用英文固定链接就用不用管文章id的事情了。

发表评论

*

*

1 + 5 = ?