给WordPress的评论和留言加道数学题

2008年10月04日 23:57 . 分类 WordPress相关 . 10 条评论 . 被踩 406 次 

文章作者:Slyar 文章来源:Slyar Home (www.slyar.com) 转载请注明,谢谢合作。

嘿嘿,这个是小寒(CGrrr.COM)要求写的,不得不写呀~据说是小寒被垃圾评论折磨的不得了才准备安个验证码的~~

咱这个不是验证码,咱看见那些鬼都不认识的图里的数字就头疼,咱这次用5岁的题目来考bots。。。

本来我是想写PHP代码的,不过考虑到大家还是喜欢插件,那我也就找了一个插件出来,正好咱也省事,嘎嘎~这个Spam插件的效果就是在留言评论之前访客必须做一道加法题,5岁的题目,不过我想bot是不会算的。。。

这个插件就是Math Comment Spam Protection Plugin,需要的点击进去下载就OK了,当然我也把插件放到了下载基地,名称是Slyar-math-protection.rar,大家也可以在我这里下载。

下载上传安装,我就不说了,需要注意的是第一次使用需要先到管理界面点击一下"Update Options",否则可能会出现错误提示。

好了,插件安装好了我们就该调用了,打开你模板里的comments.php或者其他留言板的模板,找到相应位置加入以下代码就OK了。

<?php
if ( function_exists('math_comment_spam_protection') ) {$mcsp_info = math_comment_spam_protection();?><label for="mcspvalue">Slyar给你出道题: <?php echo $mcsp_info['operand1'] . ' + ' . $mcsp_info['operand2'] . ' =?' ?></label><br/><p><input type="text" name="mcspvalue" id="mcspvalue" value="" size="40" tabindex="4" />
<input type="hidden" name="mcspinfo" value="<?php echo $mcsp_info['result']; ?>" /></p><?php } // if function_exists... ?>

里面的内容大家可以做相应修改,完成后的结果是:

利用.htaccess文件的Redirect语句重定向

2008年8月31日 0:49 . 分类 网络相关 . 9 条评论 . 被踩 277 次 

文章作者:Slyar 文章来源:Slyar Home (www.slyar.com) 转载请注明,谢谢合作。

我曾经写过一篇文章《301重定向,域名更换后跳转到新域名》,利用的是301规则来重定向域名,今天给大家另外一种方法来重定向域名,当然,它也是要用到.htaccess文件。

这次用到的是Redirect语句,它的使用更为简单:

Redirect /旧目录/旧文档名 新文档的地址

或者

Redirect 旧目录 新目录

举个例子,假如我现在要把http://www.localhost.com/blog这个目录转移到http://www.slyar.com/blog,那么我们只需要在.htaccess文件中写入以下内容并上传到http://www.localhost.com的网站根目录即可。

Redirect /blog http://www.slyar.com/blog

这样,所有对http://www.localhost.com/blog目录的请求都将被重新指向新的站点,包括附加的额外URL信息。例如有人访问

http://www.localhost.com/blog/aboutslyar.html

就会被重定向到

http://www.slyar.com/blog/aboutslyar.html

是不是很方便呢?如果利用好这个功能,那么以后换域名就不会再受损失了。

让Wordpress在导航条隐藏某个已发布的页面

2008年8月30日 1:16 . 分类 WordPress相关 . 4 条评论 . 被踩 376 次 

文章作者:Slyar 文章来源:Slyar Home (www.slyar.com) 转载请注明,谢谢合作。

有人问起如何在导航条上隐藏一个已发布的页面,实现页面可以访问但是在导航条上看不到的效果,查过Wordpress的Codex后得到方法。

Exclude Pages from List

Use the exclude parameter hide certain Pages from the list to be generated by wp_list_pages.

<ul>
<?php wp_list_pages('exclude=17,38' ); ?>
</ul>

知道了这个参数,那么解决方法也就有了:

1、在Wordpress后台得到你想要隐藏的页面ID号,比如说10号

2、打开模板文件夹下的header.php

3、查找php wp_list_pages,例如我就得到:

     <?php wp_list_pages('title_li=&depth=2&sort_column=menu_order'); ?>

4、在后面的参数表里加入一句&exclude=10(就是你想隐藏的ID号),例如我修改后就是:

     <?php wp_list_pages('title_li=&depth=2&sort_column=menu_order&exclude=10'); ?>

5、保存文件,搞定

修改php的memory限制

2008年8月28日 0:02 . 分类 网络相关 . 1 条评论 . 被踩 420 次 

文章作者:Slyar 文章来源:Slyar Home (www.slyar.com) 转载请注明,谢谢合作。

Xampp搭环境,用xml导入的时候出了点问题,可能很多人也有这样的问题吧,以前我没碰到,今天遇到了。。。

Fatal error: Allowed memory size of 33554432 bytes exhausted (tried to allocate 334230 bytes) in D:\xampp\htdocs\test.php on line56

php内存溢出了,无语。来吧,我们修改一下。

1、打开 \xampp\apache\bin\php.ini 。不要去php文件夹找那个php5.ini ,那个不是配置文件。

2、搜索 "memory" 找到以下内容:

;;;;;;;;;;;;;;;;;;;
; Resource Limits ;
;;;;;;;;;;;;;;;;;;;

max_execution_time = 60     ; Maximum execution time of each script, in seconds
max_input_time = 60    ; Maximum amount of time each script may spend parsing request data
memory_limit = 32M      ; Maximum amount of memory a script may consume (16MB)

3、修改 "memory_limit =" 的值即可,一般改成64M就差不多了。

4、重启Apache ,完毕。

修改WordPress标签云的字体大小以及显示数量

2008年8月26日 0:11 . 分类 WordPress相关 . 16 条评论 . 被踩 596 次 

文章作者:Slyar 文章来源:Slyar Home (www.slyar.com) 转载请注明,谢谢合作。

恩,有朋友问到如何修改Widgets标签云的字体大小,稍微研究了一下,发现很简单,还是修改代码!我就是喜欢改代码,嘎嘎~

因为是修改Widgets标签云,所以目标文件依旧是\wp-includes\widgets.php,打开并搜索wp_tag_cloud,这个就是标签云的调用函数了,查了一下参数表,得到wp_tag_cloud函数的参数如下:

smallest – Adjusts the size of the smallest tags in the cloud. Default is "8".
largest – Adjusts the size of the biggest tags in the cloud. Default is "22".
unit – Sets the unit type for font size (i.e. point or em). Default is "pt".
number – How many tags will display in the cloud. Default is "45".
format – "Flat" displays an inline cloud with each term separated by whitespace. "List" generates an unordered list. "Array" lets you define an array of tags. Default is "flat".
orderby – Sort the cloud by "name" or "count". Default is "name".
order – Sort the cloud in ascending or descending order. Default is "ASC".

这样结果就很明了了,如果要修改字体的大小,只要把 wp_tag_cloud(); 修改为 wp_tag_cloud('unit=px&smallest=8&largest=20'); 即可,其中:

unit=px是字体大小的单位,使用我们熟悉的px最好;

smallest=8是指最小字体大小,自己修改;

largest=20是指最大字体大小,自己修改。

还可以使用number=45来设置标签的显示数量,orderby=count来使得标签云按照标签的使用次数来排列等等。。。

好了,关于标签云函数Slyar就介绍到这里,大家自己发挥呵呵。

Wordpress友情链接 wp_list_bookmarks 函数详解

2008年8月21日 0:00 . 分类 WordPress相关 . 3 条评论 . 被踩 307 次 

文章作者:Slyar 文章来源:Slyar Home (www.slyar.com) 转载请注明,谢谢合作。

唔,今天突然发现很多人不晓得这个函数,而这个函数又是比较强大的一个,于是乎我就写写。。。

wp_list_bookmarks 这个函数也是为Blogroll服务的,比以前的函数 get_links_list() 和 get_links() 更加强大,它有很多参数,参数和参数之前用"&"分隔。详见全文。

阅读全文

关闭
E-mail It