WP留言板 DIRECTORY_SEPARATOR
时间:2009年04月08日作者:simaopig评论次数:7
网上有很多关于非插件制作WP留言板的教程,我的唠呗是按随便说说的方法制作的。
但是在引用新的评论页的时候(因为我把留言的评论内容里的一些变量对应的中文名给换了一下),却找不到这个comments.php。
结果页面又是报错又是什么的,弄得很烦。
没办法,只能一步一步调试了,报错信息如下:
看一下comment-template.php的代码如下:
$include = apply_filters('comments_template', STYLESHEETPATH . $file );
if ( file_exists( $include ) )
require( $include );
elseif ( file_exists( TEMPLATEPATH . $file ) )
require( TEMPLATEPATH . $file );
else
require( get_theme_root() . '/default/comments.php');
if ( file_exists( $include ) )
require( $include );
elseif ( file_exists( TEMPLATEPATH . $file ) )
require( TEMPLATEPATH . $file );
else
require( get_theme_root() . '/default/comments.php');
很明显,是找不到该文件才去找默认皮肤的comments.php文件。
而我又把默认皮肤给删了,所以报错是很正常的。
于是我把我guestcomments.php(templates下的)代码改为
if (function_exists('wp_list_comments')) {
comments_template('../guestcomments.php', true);
} else {
comments_template('../guestcomments.php');
}
comments_template('../guestcomments.php', true);
} else {
comments_template('../guestcomments.php');
}
在WINDOWS下面是没有问题的
,但是我的小小子是LINUX主机,把代码传上去后还是报同样的错误。
后来仔细看了一下代码,原来人家是直接用TEMPLATEPATH . $file,中间是没有文件目录分隔符的啊。。
看到这就好办了,PHP可是有自带函数DIRECTORY_SEPARATOR可以解决这个问题。
if (function_exists('wp_list_comments')) {
comments_template(DIRECTORY_SEPARATOR.'guestcomments.php', true);
} else {
comments_template(DIRECTORY_SEPARATOR.'guestcomments.php');
}
comments_template(DIRECTORY_SEPARATOR.'guestcomments.php', true);
} else {
comments_template(DIRECTORY_SEPARATOR.'guestcomments.php');
}
世界太平了。。。
声明: 本文采用 BY-NC-SA 协议进行授权 | 小小子
转载请注明转自《WP留言板 DIRECTORY_SEPARATOR》
发表评论

不错
[回复]
@时尚通讯社
呵,写在这给自己留个备忘,如果赶巧对别人又有所帮助,当然会很开心。
[回复]
貌似有点看不懂….
不是直接修改page吗?…..然后加上
[回复]
@【朝华夕拾】
不是啊。因为你看我这个页里的东西都是“发表意见”,“评论”之类的。
我让留言板和评论的是两个模板啦。
是我自己定义的一个guestbook模板。主要用了两个comments.php。
没有改page啦。
[回复]
Hi, nice post. I have been thinking about this topic,so thanks for posting. I’ll certainly be subscribing to your blog.
[回复]
@How I Lost Thirty Pounds in Thirty Days
Thank you very much!I’ll certainly be subscribing to your blog too.
[回复]
来学习了。
[回复]