升级 Wordpress

Flying
2014-06-25 / 0 评论 / 103 阅读 / 正在检测是否收录...

随着近年来推特和微博的流行,传统博客被人慢慢遗忘。想当年 Web 2.0 的年代,博客是多么的火,现在像我这样还写博客的人是越来越少了。让人感慨“三十年河东,三十年河西”。时间的原因,我的博客现在也不怎么更新了,不知道我还能坚持多久,我的目标是写十年。等到 2016 年的夏天,让它寿终正寝。

wordpress.svg

自适应大屏幕

今天将 Blog 升级到 Wordpress 3.8.1,用上了新的主题。还真不错,使用了流体网格布局,可以自适应不同屏幕分辨率的电脑及设备。不过官方称可以在后台对自带主题设置备案信息,这一新特性对 twentyfourteen 主题不起作用。其实不难改,在 wp-content\languages 找到 zh_CN.php,在最后加上 add_action('twentyfourteen_credits', 'zh_cn_l10n_icp_num')就搞定了。还有该主题在大屏幕下显示的内容太少,没能充分利用空间。可以修改 wp-content\themes\twentyfourteen 中的 style.css,将 max-width: 474pxmax-width: 1260px 全部替换为 max-width: auto 或者注释掉。另外还需要修改一下其它宽度,可参考以下 CSS 代码片段:

.gallery-columns-2 .gallery-item {
  max-width: 98%;
  max-width: -webkit-calc(100% - 4px);
  max-width: calc(100% - 4px);
}
@media screen and (min-width: 1260px) {
  .site-content blockquote.alignleft,
  .site-content blockquote.alignright {
    width: -webkit-calc(90% + 18px);
    width: calc(90% + 18px);
  }
  .site-content blockquote.alignleft {
    margin-left: -8%;
  }
  .site-content blockquote.alignright {
    margin-right: -8%;
  }
}
@media screen and (min-width: 846px) {
 .content-area,
 .content-sidebar {
    padding-top: 72px;
  }
}

这样可以自适应大屏幕。感兴趣的话,大家不妨也试一试。这个主题风格类似 Windows 8,黑色基调比较适合晚上用移动设备进行阅读。看来移动互联网越来越得人心,得人心者必得天下。

注意:Wordpress 高版本还使用了 CSS3 @font-face,本来这没有任何问题。问题在于字体链接到 http://fonts.googleapis.com/css,这就惨了,得翻墙都得访问该文件,不然会阻塞页面其它资源的加载。解决方法是将下载相关 Lato、OpenSans 字体,然后将链接指向本地路径。具体需要修改 wp-content\themes\twentyfourteen\functions.phpwp-includes\script-loader.phpwp-includes\js\tinymce\plugins\compat3x\css\dialog.css,将 //fonts.googleapis.com/css 全部替换为本地路径。

禁用版本

/** WordPress 目录的绝对路径。 */前面添加:

// 禁用版本
define('WP_POST_REVISIONS', false);
// 一天后自动保存
define('AUTOSAVE_INTERVAL', 86400);

ID 的连续性

还有一个普遍问题就是禁用草稿保持文章 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' );
// WordPress 连续 ID,禁用草稿功能函数结束

// 使 WordPress 在原生编辑器(tiny)下发表文章时,不去除空格
add_filter('tiny_mce_before_init', 'preserve_nbsp_chars');
function preserve_nbsp_chars($initArray) {
  $initArray['entities'] = '160,nbsp,'.$initArray['entities'];
  return $initArray;
}

看得出 Wordpress 升级很麻烦,不得已就不要试了。

5

评论 (0)

取消