[实测]WordPress随机显示分类名称的代码

有百度知道有知友提出问题:

wordpress有插件可以随机显示分类项目吗?注意是分类项目不是文章。可以不用的插件就最好。

链接地址:http://zhidao.baidu.com/question/500324413023524444.html

很早前,我发布了一篇关于wordpress随机文章的进阶用法。此次该知友的需求不同于此;所以我重新针对该知友的需求,编写并测试了如下代码:
Continue reading [实测]WordPress随机显示分类名称的代码

Wamp Server 2.5 环境下安装memcache扩展的全过程

使用wordpress也好多年了,但从来没去研究过缓存机制;今天仔细阅读了我爱水煮鱼关于wordpress性能优化的文章,决定学习和了解一下memcached;
百度了很多很多别人分享安装的文章,导致安装过程曲折离奇。
直至最后安装好,才发现:所有的问题全因自己缺乏对应用环境的了解!
现记录下来,一并整理自己所遇到的坑。

一、操作系统

Windows 7 旗舰版 64位操作系统

二、Wamp Server 2.5环境

Apache/2.4.9 (Win32)
PHP/5.5.12

三、安装Memcached

3.1 概念

Memcached 是以 LiveJournal 旗下 Danga Interactive 公司的 Brad Fitzpatric 为首开发的一款分布式缓存服务器,基于内存,性能非常高,现在已成为mixi、hatena、Facebook、Vox、LiveJournal等众多服务中提高Web应用扩展性的重要因素(更多介绍参见:维基百科百科百科)。
Continue reading Wamp Server 2.5 环境下安装memcache扩展的全过程

[亲测]成功解决因360前端公共库停止服务引起的问题

2016年08月31日,360网站安全卫士前端公共库宣布停止服务,具体请看公告内容
国内很多网站在google被墙后选择切换至360前端公共库,包括我在内;导致这个月因360前端公共库停止服务,网站打开超慢。

我曾在14年发布轻松解决被谷歌免费字体库拖慢的现象一文,其中正是将字体库更换为360前端公共库。

可喜的事是,google的字体库又恢复了,详细信息可参考Hao Lee于知乎的阐述:https://www.zhihu.com/question/24955477/answer/120232550
Continue reading [亲测]成功解决因360前端公共库停止服务引起的问题

有效恢复MYSQL受损数据

突然断电,重启后导致个人电脑中的wordpress数据库受损;
此数据是在本地经过很长一段时间的录入、维护的,而且在本地从末因断电或其他原因导致的数据损坏,故没有备份。所以很心塞!

故障从wamp(wamp server 2.5)服务无法正常启动开始,查apache错误日志和mysql日志以及计算机事务日志,找到关键提示:

InnoDB: We do not continue the crash recovery, because the table may become
InnoDB: corrupt if we cannot apply the log records in the InnoDB log to it.
InnoDB: To fix the problem and start mysqld:
InnoDB: 1) If there is a permission problem in the file and mysqld cannot
InnoDB: open the file, you should modify the permissions.
InnoDB: 2) If the table is not needed, or you can restore it from a backup,
InnoDB: then you can remove the .ibd file, and InnoDB will do a normal
InnoDB: crash recovery and ignore that table.
InnoDB: 3) If the file system or the disk is broken, and you cannot remove
InnoDB: the .ibd file, you can set innodb_force_recovery > 0 in my.cnf
InnoDB: and force InnoDB to continue crash recovery here.
2016-08-19 09:26:26 5488 [Note] Plugin ‘FEDERATED’ is disabled.

原因是mysql发生crash错误导致无法恢复而引起的wamp启动失败!
Continue reading 有效恢复MYSQL受损数据

【小技巧】如何让wordpress首页不显示某一分类文章

在百度知道可以遇到很多场景下的不同需求,如这位道友提出的问题:

如何让wordpress首页不显示某一分类文章
http://zhidao.baidu.com/question/810859304090448132

场景: 首页
需求: 不显示某一分类的文章
大致实现的代码如下:

add_action( 'pre_get_posts', 'wpdit_pre_get_posts' );
function wpdit_pre_get_posts( $wp_query ) {
    if ( is_home() || is_front_page() ){
        $wp_query->set( 'category__not_in', array(1) ); // 1为不想显示的分类ID
    }
    return $wp_query;
}

Continue reading 【小技巧】如何让wordpress首页不显示某一分类文章