有很多WordPress博客的固定链接中使用了文章ID,但是WordPress由于种种原因导致了文章ID不连续的问题。
对于有着轻微强迫症,追求完美的朋友来说,这的确很让人讨厌。
在WordPress后台并没有直接的提供关闭这个功能的选项,那么该如何解决文章ID不连续的问题呢?今天就给大家讲讲如何把这个功能完完全全的隐蔽掉。
找到当前主题目录,在主题目录下到文件functions.php,将下述代码添加到文件里面。
//WordPress解决文章ID不连续的问题function keep_id_continuous(){global $wpdb;$lastID = $wpdb->get_var(“SELECT ID FROM $wpdb->posts WHERE post_status = ‘publish’ OR post_status = ‘draft’ OR post_status = ‘private’ OR ( post_status = ‘inherit’ AND post_type = ‘attachment’ ) ORDER BY ID DESC LIMIT 1”);$wpdb->query(“DELETE FROM $wpdb->posts WHERE ( post_status = ‘auto-draft’ OR ( post_status = ‘inherit’ AND post_type = ‘revision’ ) ) AND ID > $lastID”);$lastID++;$wpdb->query(“ALTER TABLE $wpdb->posts AUTO_INCREMENT = $lastID”);}add_filter( ‘load-post-new.php’, ‘keep_id_continuous’ );add_filter( ‘load-media-new.php’, ‘keep_id_continuous’ );add_filter( ‘load-nav-menus.php’, ‘keep_id_continuous’ );//禁用自动保存,所以编辑长文章前请注意手动保存。add_action( ‘admin_print_scripts’, create_function( ‘$a’, “wp_deregister_script(‘autosave’);” ) );//禁用修订版本remove_action( ‘pre_post_update’ , ‘wp_save_post_revision’ );