Word2007新增了不少WEB功能,最近发现用它写博客蛮方便的。直接输自己WordPress的地址,账号便可以发布、修改博文。
具体的步骤大家打开Word2007一定很快就发现怎么用了。
这里贴出自己遇到的若干问题,以及解决方法:
1. 添加账号时,提示无法连接到博客提供商
1.a) 首先确认你的博客设置中Writing里的”Enable the Atom Publishing Protocol” 和 “Enable the WordPress, Movable Type, MetaWeblog and Blogger XML-RPC publishing protocols” 这两个选项已经勾上。这是启用XMLRPC,只用启用了此功能,Word才能连接到博客。
1.b) 如果已经启用了,但仍然无法连接,那么很可能是你的WordPress经过了手工编辑,可能是你自己编辑,也可能是安装包已经是经过修改的。而在修改时有相关文件被加上了UTF8编码标记。
打开wp-includes/class-IXR.php 文件,找到
$length = strlen($xml); header('Connection: close'); header('Content-Length: '.$length); header('Content-Type: text/xml'); header('Date: '.date('r')); echo $xml; exit;
这段代码,大概应该在395行的样子,将设置Content-Length这句注释掉:
$length = strlen($xml); header('Connection: close'); header('Content-Length: '.$length); //header('Content-Type: text/xml'); header('Date: '.date('r')); echo $xml; exit;
因为这句话设置了反馈给Word的内容的长度,而一旦内容中包含了UTF8编码标记的话,将会导致xml文档内容不完整,而使得Word无法正常解析。显然不设置这句,PHP也会自动计算出长度的。
2. 打开现有文章时,文章内容不全。
细心的人会发现,凡是加入了“More”标记的文章,打开后都只能显示More之前的内容。这个不知道为什么会这样设计,反正WordPress的设计者就这么干了,我们可以改一下代码。
打开根目录下的xmlrpc.php文件。找到如下代码片段(大概在2630行):
$resp = array( 'dateCreated' => new IXR_Date($post_date), 'userid' => $postdata['post_author'], 'postid' => $postdata['ID'], 'description' => $post['main'], //这个$post['main']是上面计算出来的More标签之前的摘要内容 'title' => $postdata['post_title'], 'link' => $link, 'permaLink' => $link
其中的$post['main']替换成$postdata['post_content']即可。这样即是返回全文:
$resp = array( 'dateCreated' => new IXR_Date($post_date), 'userid' => $postdata['post_author'], 'postid' => $postdata['ID'], 'description' => $postdata['post_content'], //返回全文 'title' => $postdata['post_title'], 'link' => $link, 'permaLink' => $link
OK,我就遇到这两个问题了。最近在研究将WordPress改造成电子商务网站,有成果了再跟大家分享。