文章 ID 不连续是很多 “强迫症” 博主的烦恼,尤其是使用了文章 ID 作为固定连接之后,每篇文章的 ID 并不连续,非常不好。
从原因来看,文章 ID 不连续主要是因为自动保存的文章、媒体、页面和其它文章类型占用了 ID 导致的,网上的解决方法一般是强制的禁止自动草稿、不在媒体库上传媒体、不建立页面等等,但这种方法会导致使用上的不便利,而且很有局限性。
解决方案
本文说的方法也是治标不治本,但却能比较好的解决链接上的 ID 不连续这个问题。这个方法就是利用别名,自动给文章设置一个别名,别名按顺序递增,然后把固定连接设置成别名。
描述 但是默认 WordPress 使用帖子修订将每个帖子修订保存在您的数据库中。如果您关心服务器和数据库大小,这些帖子修订可能会令人头疼。 如果您觉得您不想要某个帖子类型的帖子修订功能,您不能简单地从设置页面禁用它。但有了这个插件,这很容易。
https://cn.wordpress.org/plugins/disable-post-revision/
.
*
* @category Core
* @package JJ4T3
* @author Joel James <me@joelsays.com>
*/
// If this file is called directly, abort.
defined( 'ABSPATH' ) or exit;
if ( ! class_exists( 'Disable_Post_Revision' ) ) :
/**
* The public-facing functionality of the plugin.
*
* This class contains the public side functionalities like,
* logging, redirecting etc.
*
* @category Core
* @package DPR
* @subpackage Public
* @author Joel James <me@joelsays.com>
* @license http://www.gnu.org/licenses/ GNU General Public License
* @link https://thefoxe.com/products/disable-post-revision
*/
class Disable_Post_Revision {
/**
* Initialize the class and set its properties.
*
* @since 1.0.0
* @access public
*
* @return void
*/
public function __construct() {
add_action( 'admin_init', array( $this, 'disable_revisions' ) );
add_action( 'admin_init', array( $this, 'options_page' ) );
}
/**
* Remove post revision support for the selected types.
*
* @since 1.0.0
* @access public
* @uses get_option() To get the option value.
* @uses remove_post_type_support() To remove the revision feature.
*
* @return void
*/
public function disable_revisions() {
$post_types = get_option( 'dpr_disabled_types', array() );
if ( !is_array( $post_types ) || empty( $post_types ) ) {
return;
}
foreach ( $post_types as $post_type ) {
remove_post_type_support( $post_type, 'revisions' );
}
}
/**
* Create new options field to the writing settings page.
*
* @since 1.0.0
* @access public
* @uses register_setting() To register new setting.
* @uses add_settings_field() To add new field to for the setting.
*
* @return void
*/
public function options_page() {
register_setting( 'writing', 'dpr_disabled_types' );
// If options not found, set an empty array.
if ( !get_option( 'dpr_disabled_types' ) ) {
update_option( 'dpr_disabled_types', array() );
}
add_settings_field(
'dpr_label', '', array( &$this, 'fields' ), 'writing'
);
}
/**
* Create new options field to the writing settings page.
*
* @since 1.0.0
* @access public
* @uses get_option() To get the option value.
* @uses get_post_types() To get the available post types.
*
* @return void
*/
public function fields() {
// Get settings value.
$value = get_option( 'dpr_disabled_types', '' );
// Get available post types.
$post_types = get_post_types( array(), 'objects' );
echo '';
echo '
' . __( 'To select multiple post types, hold ctrl key while selecting', 'disable-post-revision' ) . '
';
echo '
' . __( 'Note', '' ) . ': ' . __( 'Do not select a post type if you are not sure about it', 'disable-post-revision' ) . '
';
}
}
// Begins execution of the plugin.
new Disable_Post_Revision();
endif;
// *** Thank you for your interest in Disable Post Revisions - Developed and managed by Joel James *** //