10 Reasons To Have A Custom Blog

This item was filled under [ Create Your Personal Blog ]

Blogging is a growing trend on the Internet today with hundreds of users adding new blogs and fresh content daily.While many use their blogs for personal journals, political opinions or other topics of discussion, one could also look at a blog from a marketing perspective and find benefits for their business. Here I suggest ten reasons to start a custom blog to enhance their online marketing efforts.
阅读更多…

Bookmark and Share

Giving WordPress its Own Directory While Leaving Your Blog in the Root Directory

This item was filled under [ wordpress tips ]

Many people want WordPress to power their site’s root (e.g. http://example.com) but they don’t want all of the WordPress files cluttering up their root directory. WordPress allows you to install the WordPress files to a subdirectory, but have your blog exist in the site root. 阅读更多…

Bookmark and Share
Tagged with: [ ]

wpaffiliate, one famous wordpress affiliate plugin

This item was filled under [ wordpress plugins ]


Adsense Alternative – Earn More Revenue With The ClickBank Affiliate Program

Unless your Google Adsense income rocks, chances are you probably earn cents per click. Thanks to the WordPress Affiliate ClickBank Plugin you can now utilize ClickBank, one of the biggest affiliate networks on the Internet. Earn up to 75% commission per sale. ClickBank offers over 12,000 digital products with instant delivery, therefore making ClickBank affiliate ads the very best alternative to Adsense.

All Links With Your Affiliate ID Will Pay FULL Commission

The WordPress Affiliate ClickBank Plugin is unique because unlike with other similar plugins on the market I didn’t hide affiliate links in my product. Neither do I charge you a commission on your sales for using this plugin. You get to keep 100% of your sales commissions – just as it should be!
阅读更多…

Bookmark and Share

wordpress query_posts()

This item was filled under [ wordpress tips ]

将query_posts()放在LOOP之前限定你所需要的条件,wp_query会产生一个新的使用你的参数的SQL查询,而忽视通过URL接收到的其它的参数,如果想不忽略,可以在调用中使用$query_string。

query_posts($query_string . “&order=ASC”)

设置文章显示的顺序,但是不干扰其余的查询字符串,参数前须有“&”符号

其他还有N多用途~~

* 主页不显示某一分类下的日志

if (is_home()) {
query_posts("cat=-3");
}
?>

* 获得特定的日志

query_posts('p=5');
?>

* 获得特定的页面

query_posts('page_id=7'); //只返回网页7
?>

query_posts('pagename=about'); //只返回关于网页
?>

query_posts('pagename=parent/child'); // 返回母网页的子网页
?>

* 创建所有文章列表,并且提供分页功能

query_posts($query_string.'posts_per_page=-1');
while(have_posts()) { the_post();
put your loop here ;
}
?>

==========================================
类别 参数

显示属于某个类别的文章

* cat
* category_name

根据ID显示一个类别

只显示来自一个类别ID的文章

query_posts(‘cat=4′);

根据名称显示一个类别

只显示属于某个类别名的文章

query_posts(‘category_name=Staff Home’);

显示几个类别及ID

显示属于几个类别ID的文章

query_posts(‘cat=2,6,17,38′);

删除某个类别的文章

显示所有的文章,但是类别ID前面有个’-’(负号)负号的类被除外。

query_posts(‘cat=-3′);

删除属于类别3的所有文章。有一个限制性条款:会删除只属于类别3的所有文章。如果一个类别也同时属于其它的类别,这个类别仍然不会被删除。
标签参数

显示与某个标签相关的文章

* tag

为某个标签提取文章

query_posts(‘tag=cooking’);

获得拥有任何这样的标签的文章

query_posts(‘tag=bread,baking’);

获取拥有这三个标签的文章

query_posts(‘tag=bread+baking+recipe’);

作者参数

你也可以根据作者限制文章数目

* author_name=Harriet
* author=3

author_name在 user_nicename区操作, 同时作者 在作者id上操作。
文章 & 网页参数

返回一篇单独的文章或者一个单独的网页

* p=1 – 使用文章 ID来显示第一篇文章
* name=first-post – 使用 post Slug 显示第一篇文章
* page_id=7
* pagename=about
* showposts=1 (你可以使用 showposts=3,或者其它的任何数字显示一定数目的文章)

由于 模板层级方面的原因, home.php先执行了。这意味这你可以编写一个home.php,home.phh调用query_posts()重新得到一个特别的网页并且将那个网页设置为你的首页。没有任何插件或者hacks,你需要运行一个机制,并且显示和维护一个非博客的首页。

更有用的方法,可能是利用WP的网页功能并且为你的首页使用这个功能。你可以将”关于网页”设置为entry point或者设置为站点的末页。你可能执行一些更动态的步骤,设置一个自定义网页,显示最近的评论,文章,类别,存档。请看看下面的例子。
时间参数

得到某个特别的时间段内发表的文章

* hour=
* minute=
* second=
* day= – 一个月中的每一天; 显示,例如,十五号发表的所有文章。
* monthnum=
* year=

网页参数

* paged=2 -显示使用”以前发表的文章”链接时,通常在网页2上显示的文章。

* posts_per_page=10 -每个网页显示的文章数目;-1这个值,会显示所有的文章。

* order=ASC -按时间顺序显示文章,以相反的顺序显示DESC(默认)

Offset 参数

你不能转移或者忽视一个或者更多的原始文章,这些文章一般是你的query同时使用offset参数收集到的。

下面的函数会显示(1)最近的5篇文章

query_posts(’showposts=5&offset=1′);

根据参数排序

根据这个区给得到的文章排序

* orderby=author
* orderby=date
* orderby=category
* orderby=title
* orderby=modified
* orderby=modified
* orderby=menu_order
* orderby=parent
* orderby=ID
* orderby=rand

同时考虑”ASC”或者的”DESC”的排序参数
联合参数

你可能从上面的例子中注意到,你使用一个&(&符号)将参数组合在一起,像:

query_posts(‘cat=3&year=2004′);

类别13,关于当前月份显示在主页上的文章:

if (is_home()) {
query_posts ($query_string . ‘&cat=13&monthnum=’ . date(‘n’,current_time(‘timestamp’))); }

在2.3版本中,这个参数组合会返回属于类别1同时属于类别3的文章,只显示两篇(2)文章,根据标题,按降序排列:

query_posts(array(‘category__and’=>array(1,3),’showposts’=>2,’orderby’=>title,’order’=>DESC));

在2.3和2.5版本中,你可能期待下面的内容,返回属于类别1并且标签为”苹果”的所有文章

query_posts(‘cat=1&tag=apples’);

一个bug阻止这个运行。请看看Ticket #5433,一个工作区要搜索几个使用+的标签

query_posts(‘cat=1&tag=apples+apples’);

对于先前的查询,这个会产生期待的结果。注意使用’cat=1&tag=apples+oranges’能够产生期待的结果。

Bookmark and Share

blog域名迁移之迁移wordpress

This item was filled under [ wordpress tips ]

迁移wordpress主要涉及到3步:

1、数据备份

如果服务器上装有phpmyadmin,可以直接导出一下。使用shell的朋友,可以用如下命令来备份数据:

mysqldump  -u dbuser -pdbpass -h  dbhost  dbname | gzip > backup.sql.gz

把相应位置的dbuser, dbpass, dbhost和dbname替换为数据库用户名、密码、数据库服务器以及要备份的库名。最后得到的backup.sql.gz,就是一份完整备份。

插一句,我把备份的文件解压一看,居然有12M之巨。如果10%是有效内容的话,我这4年已经写了1.2M字节,相当于60万汉字了。

2、配置Web服务器

在这里需要牢记一点:使用301跳转,而不要用默认的302refer)。

配置Web服务器的目的是,将访问原有域名的请求引导到新的域名。301跳转是永久重定向,而302跳转是暂时重定向。前者对搜索引擎更为友好。

在nginx中做如下配置:

server {
listen   80;
server_name  oldhost.com www.oldhost.com newhost.com;
rewrite ^/(.*) http://www.newhost.com/$1 permanent;
}

server{
listen  80;
server_name  newhost.com;
……
}

第一段的配置是将oldhost.com,www.oldhost.com,newhost.com的请求都重定向到www.newhost.com 下面。而第二段是用www.newhost.com替换原有的www.oldhost.com,其他部分不用改变。注意到在使用rewrite时,加入了 permanent关键字,可以使nginx发送301重定向。

如果使用apache,配置也类似,在rewrite时可加入参数R=301。

保存之后重启web服务器,使配置生效。

3、修改数据库

这也是对wordpress进行迁移的最后一步。需要注意,在完成第二步之后,wordpress会暂时无法打开,原因大家可以自己考虑一下。如果觉得不太好,把这一步提到前面也可以。或者可以先修改好配置文件,等第三步完成了再重启web服务器。

修改数据库主要修改3部分,语句可以在phpmyadmin或者mysql命令行中进行,整理自此处

(1)修改站点地址、主页地址:

UPDATE wp_options SET option_value = replace(option_value, ‘http://www.old-domain.com’, ‘http://www.new-domain.com’) WHERE option_name = ‘home’ OR option_name = ’siteurl’;

(2)修改文章中内部链接以及附件地址:

UPDATE wp_posts SET post_content = replace(post_content, ‘http://www.old-domain.com’, ‘http://www.new-domain.com’);

(3)更新文章永久链接:

UPDATE wp_posts SET guid = replace(guid, ‘http://www.old-domain.com’,’http://www.new-domain.com’);

这三板斧一过,wordpress的迁移已经完成了。之后就从新域名打开网站,看看是否还有什么地方遗漏未能改掉。

BTW,如果原来域名有备案的话,可以在页面底部去掉。更换域名以后,就失效喽。

Bookmark and Share

使用ghost-blog,让你的wordpress成为一个超级cms

This item was filled under [ wordpress plugins ]

这个插件可以让你的blog有个ghost功能,如果你想创建一个cms,比如类似学校课程的列表,会按照不同专业列出课程,不同的专业可能会有相同的专业课或选修课程,这个时候,你可以建多个文章标题比如: 

website

-php

–wordpress

-html

–wordpress(for designer)

 

此时,你可能想要2个跟wordpress的文章的内容一样,并且,改变其中一个的时候,另一个也同时改变,就像是一篇文章的内容,可以放到2个文章里一样。

在你想ghost的blog内容里写上你要ghost的文章id即可类似如此: [ghost=897]

这样插件就会自动获取id为897的文章的内容。

 

This plugin would let your blog got a ghost function,just like if you want to create a cms system,like a course list for different specialities,but for different specialities,there must be some courses would be the same,for then,you could create different blog post or page to to this:

website

-php

–wordpress

-html

–wordpress(for designer)

 

Then, you maybe want two of the wordpress course got the same content, and when you change one of the content,then all of the other content would be change,just like you put one content in two blog posts.

Check out the plugin URL, for more information.

Put the tag into the new post that you want to ghost: [ghost=897]

Then the plugin would automaticly get the content of the post 897(the post id) to the new blog you want to be show

Bookmark and Share

wordpress help sheet,wordpress实用帮助小抄[持续更新中]

This item was filled under [ wordpress tips ]

get_post_custom()
Get all key/value data for the current post.
get_post_custom_keys()
Get a list of all key names for the current post.
get_post_custom_values($key)
Get the list of values for a particular key on the current post.
get_post_meta($post_id, $key, $single = false)
In WP 1.5 and beyond, this function returns the meta information without cache problems. The function requires the post id, the key, and if $single is set to TRUE, it returns only the first result (NOT as an array) for PHP use.

忘记admin密码,可以这样
修改MD5密码为:”5d41402abc4b2a76b9719d911017c592″,然后使用“hello”登录
得到的字符串,就是加密后的admin。在phpmyadmin里更新下admin帐号的密码为这个新的字段

获取图片地址:

$search = ‘/<img[^\>]*src=\”(.+?)\”.*\/>/’;

$img_arr = ”;

if (preg_match_all($search, $content, $matches, PREG_SET_ORDER))

{

foreach ($matches as $match)

{

$img_arr[] = $match[1];

$content = str_replace($match[0], ”, $content);

}

}

wordpress迁移,数据库修改语句

UPDATE wp_options SET option_value = replace(option_value, ‘old’,'new’) WHERE option_name = ‘home’ OR option_name = ’siteurl’;

UPDATE wp_posts SET post_content = replace(post_content,’old’,'new’);

UPDATE wp_posts SET guid = replace(guid, ‘old’, ‘new’);get_post_custom()
Get all key/value data for the current post.
get_post_custom_keys()
Get a list of all key names for the current post.
get_post_custom_values($key)
Get the list of values for a particular key on the current post.
get_post_meta($post_id, $key, $single = false)
In WP 1.5 and beyond, this function returns the meta information without cache problems. The function requires the post id, the key, and if $single is set to TRUE, it returns only the first result (NOT as an array) for PHP use.

忘记admin密码,可以这样
修改MD5密码为:”5d41402abc4b2a76b9719d911017c592″,然后使用“hello”登录
得到的字符串,就是加密后的admin。在phpmyadmin里更新下admin帐号的密码为这个新的字段

获取图片地址:

$search = ‘/<img[^\>]*src=\”(.+?)\”.*\/>/’;

$img_arr = ”;

if (preg_match_all($search, $content, $matches, PREG_SET_ORDER))

{

foreach ($matches as $match)

{

$img_arr[] = $match[1];

$content = str_replace($match[0], ”, $content);

}

}

wordpress迁移,数据库修改语句

UPDATE wp_options SET option_value = replace(option_value, ‘old’,'new’) WHERE option_name = ‘home’ OR option_name = ’siteurl’;

UPDATE wp_posts SET post_content = replace(post_content,’old’,'new’);

UPDATE wp_posts SET guid = replace(guid, ‘old’, ‘new’);

博客换地址后,解决You do not have sufficient permissions to access this page.的问题。

UPDATE `prefix_usermeta` SET `meta_key` = REPLACE( `meta_key` , 'wp_', 'prefix_' );

(Make sure you do backups first! Note that the quotes used for string and field name are different.)

In the options table, there is ‘wp_user_roles’, make sure you get that changed into ‘prefix_user_roles’.

UPDATE `prefix_options` SET `option_name` = 'prefix_user_roles' WHERE `option_name` ='wp_user_roles' AND `blog_id` =0;

Bookmark and Share

wordpress永久链接格式建议

This item was filled under [ wordpress tips ]

wordpress永久链接用什么格式比较好?

其实这个问题没有统一的答案,因为各有各的说法,如果一定要一个确切的答案,那么我就给出两个永久链接格式建议:

  1. /html/%postname%.html
  2. /html/y%year%/%post_id%_%postname%.html

首先我来说说第一种永久链接格式的好处:

  1. 路径比较浅,所有的post都在html目录下,有利于SEO;
  2. 结尾是html,当今后访问量急剧上升,可以使用cos-html-cache静态化,由于都是在目录html,静态化之后不至于搞乱wordpress本身程序目录;
  3. 个人blog,假设可以坚持10年,一天一篇日志,也不过3000多篇日志,所以即使静态化,html目录下也仅仅不到10000个文件,不足以影响磁盘I/O效率;

相比之下,第二种永久链接的格式的优点在于,即使一年上万日志的静态化文件也不至于影响到磁盘的I/O性能,缺点在于目录层次太深,对SEO稍微不 利。第二种链接格式中的y%year% 为啥要加字母前缀呢?目的是为了防止静态化之后和默认的归档链接冲突,你可以加前缀字母”y”,当然也可以是其他字母,也可以是后缀!

综上,若你是个人blog,完全可以用第一种wordpress永久链接格式,若是团队blog,考虑到今后的扩展,建议用第二种格式!

Bookmark and Share

Wordpress Rewrite / Permalink内部过程分析

This item was filled under [ wordpress tips ]

本文说明WP 对URL rewrite并生成当前请求的过程. 实际内容并不复杂, 说的比较啰嗦啦…

关于Query Vars
这是Wordpress全部代码中最重要的变量,所谓的query vars是一系列变量集合. WP通过解析URL设定query vars, 并通过分析query vars值决定显示那些文章,设定标志位等.所谓标志位是WP_Query类中一系列$is_xxx形式布尔成员变量,所有的is_xxx()形式 template tag实际上都是返回$wp_query里对应成员变量值.  举例而言,如果当前页面是单篇文章, 则p这个Query Var(以下简称变量)值不为空.(在WP类里空的query var根本不存在,而WP_Query类里如果对应name的query var没有设置,$wp_query->query_vars['varname']被填充为空值), 如果当前为搜索页, s变量值则为搜索关键字. 如果p和page两个变量都不为空值, 则当前为单篇文章分页页面, 依次类推. Query Vars在WP类($wp)里根据WP_Rewrite里的rewrite规则生成, 在WP_Query($wp_query)类里这些变量被用来建立主循环.

WP和WP_Query类里都有query_vars成员变量,键值为query vars里的varname. 具体的query vars包括’m', ‘p’, ‘posts’, ‘w’, ‘cat’, ‘withcomments’, ‘withoutcomments’, ’s’, ’search’, ‘exact’, ’sentence’, ‘debug’, ‘calendar’, ‘page’, ‘paged’, ‘more’, ‘tb’, ‘pb’, ‘author’, ‘order’, ‘orderby’, ‘year’, ‘monthnum’, ‘day’, ‘hour’, ‘minute’, ’second’, ‘name’, ‘category_name’, ‘tag’, ‘feed’, ‘author_name’, ’static’, ‘pagename’, ‘page_id’, ‘error’, ‘comments_popup’, ‘attachment’, ‘attachment_id’, ’subpost’, ’subpost_id’, ‘preview’, ‘robots’, ‘taxonomy’, ‘term’, ‘cpage’等公开变量,以及一些private变量. private变量不能由rewrite/GET等方式生成, 所以我们这里说的都指公开变量(public query vars)

准备知识:WP初始化过程:
基本过程是index.php  ->wp-blog.header.php ->wp-load.php .

通过wp-load.php 先后包含了wp-config.php, wp-setting.php,classes.php,fucntions.php query.php等文件,并建立了三个全局变量,$wp_the_query,$wp_rewrite和$wp ,分别为WP_Query,WP_Rewrite和WP类的实例,另外建立了一个$wp_query=&$wp_the_query, (之所以这样做是为了通过query_posts等方式新建自定义查询时不会损坏WP主循环,在自定义查询结束后可以调用wp_reset_query 把$wp_query还原为$wp_the-query引用). 然后,wp-blog-header执行wp()函数,并通过其调用$wp所属WP类的main方法,这个方法又调用一系列方法,但最重要的是 parse_request方法, WP从这里开始解析URL并建立主循环.

我们假设使用了友好的permalink,并且通过Apache下.htaccess实现. 那么 ,WP类的parse_request方法建立一个$request变量,这个变量值是$_SERVER['REUEST_URI'] 或$_SERVER['PATH_INFO']经过处理后的值, 是request_uri还是path_info取决于当前是否URL是否pathinfo类型请求. 处理过程包括,移除request_uri和path_info里?以后部分(即所有GET参数). 去除request url开始的/ ,  如果你WP安装在子目录(如wordpress/目录), 从(request_uri和pathinfo)开头去除wordpress/ , 去除末尾的’/’ , 对request_uri进行rawurldecode等. ($_SERVER['PATH_INFO']的值已经是decode过的了,所以无需由wp处理).当一切完成后, $request就是一个规范化的当前请求filename, 形如 post-slug, date/YYYY/mm, tag/tag-slug之类 , 接下来,WP根据rewrite规则逐条对$request进行匹配(preg_match), 如果找到一个匹配, 建立相关的变量(query vars);如果没有任何匹配,则为404

所谓的Rewrite规则就是关联数组, 键值为用来匹配$request的正则表达式, 值为解析的变量, 如’([0-9]+)(/[0-9]+)?/?$’ => ‘index.php?p=$matches[1]&page=$matches[2]‘ 就是一条规则. 具体解析过程稍后会有介绍.在WP类里会调用$wp_rewrite的wp_rewrite_rules方法获取rewrite规则.注意Rewrite 规则有缓存的, 保存在数据库wp_option表,option name为rewrite_rules.如果数据库里这个option值为空,wp_rewrite_rules()会根据你的permalink structure重新生成rewrite规则, 并保存到数据库中.在后台更改永久链接结构时也会重新生成rewrite规则并保存到数据库中.

具体的过程,举例说明,如果你使用了 /%post_id% 形式的permalink, 当前URL是 http://domain.com/18. 解析出来的$request则是18 . WP对rewrite数组里每条规则$match用preg_match(“!^$match!”, $request, $matches)语句尝试匹配, 发现$request与 ‘([0-9]+)(/[0-9]+)?/?$’ => ‘index.php?p=$matches[1]&page=$matches[2]‘ 这条规则匹配, preg_match把 ‘18′ 和空值保存到$matches数组里, 然后WP提取出匹配项值?后部分’p=$matches[1]&page=$matches[2]‘,对这个字符串$query执行 eval(“@\$query = \”" . addslashes($query) . “\”;”);语句, 这句的目的是把$matches[1]替换为18, 把 $matches[2]替换为空. 所以$query值变为’p=671&page=’, 然后执行parse_str($query, $perma_query_vars); 这样现在$perma_query_vars数组里就有键值’为p’和’page’的值.  但这还不是最终的query vars, 最终生成的query vars是$GLOBALS, $_POST, $GET和$perma_query_vars里键值为变量名项集合.依次判断. 如果 $_POST['varname']存在,则varname这个query var值为$_POST['varname'], 而不再继续判断$_GET['varname']和$perma_query_vars['varname']是否存在, 如此类推. 最后生成的query vars保存在 $wp->query_vars里.

如果使用的是默认的/?p=123 permalink形式,那么上面过程简单的多,只会从$GLOBALS, $_POST, $GET里提取query vars变量值,而不会解析REQUEST_URI和PATH_INFO.

上面过程完成后会执行parse_request这个Action,然后执行$wp的query_posts方法,这个方法 把$wp->query_vars传给$wp_the_query的query方法,开始建立主循环,设定标志位(is_home, is_page …)等.接下来就是载入模板显示页面内容了.

下面分析一些问题:
1. 假设permalink设置为/%post_id%, 数据库中有id为 10和11的两篇文章, 访问http://domain.com/10/?p=11 ,显示什么内容?- -
答案是会显示id为11的文章,因为上面说的, $_GET里变量优先级高于rewrite rules里解析出来的变量($perma_query_vars),所以最后的p变量值为11.但这时WP通常会把当前页重定向到http://domain.com/11, 因为WP有canoninol机制(wp-includes/canonical.php),能够301重定向一些不规范地址到规范url, 典型的如把其他域名重定向到后台HOME和SITEURL里设定的域名里页面.但WP的canonical机制并不完善, 个人推荐使用permalink validator插件,这个插件判断当前URL与官方URL是否完全匹配,如果不匹配要么重定向,要么set 404,..

2. 假设permalink设置为/%post_name%, 访问http://domain.com/index.php/%post_name%结果如何?
如果对应slug的post存在的话, 不会是404. 因为虽然你permalink没有设置为index.php形式的path info permalink,但如上面所说,WP在解析URL时并不判断后台设定的永久链接结构是path info还是request uri类型或者甚至是默认/?p=123类型. 不过这时通常会重定向到http://domain.com/%post_name% , 同样因为canonical机制.

3. 关于URL末尾的 ‘/’
URL末尾是否有/对rewrite没有影响, 如上所述, WP类在生成$request时会去除requset_uri和path_info末尾/ ,另外,你注意到所有WP生成的rewrite规则, 键值正则式的末尾均为  /?$ ,表示URL末尾可选 / .  不过wp会判断当前URL末尾是否有/ 以及后台设置的permalink末尾是否有/, 如果不一致则301重定向, 还是因为canonical代码. 请注意WP的 canonical代码在template_redirect这个action处执行,这时WP实际上已经解析完query vars, 主循环也设置好了, 即将载入模板..

4. 假设permalink设置为/%post_name%,数据库里两个有slug都为’about’的post和page,访问http://domain.com/about, 显示哪个?
这种情况由rewrite规则数组顺序决定, 通常wp生成的rewrite规则里 ‘(.+?)(/[0-9]+)?/?$’ => ‘index.php?pagename=$matches[1]&page=$matches[2]‘ 这条规则是最后一个, 所以这时会显示post而不是page.

5. 有人使用”古怪”的permalink结构,如/?p=%post_id%.html, 然后发现所有分类/tag页全部显示最新文章= =
原因是在这种古怪的permalink结构下,WP根本无法正确获取query vars变量,无论从GET还是url rewrite,因为如上面所说,wp rewrite 的第一步就是去除request_uri和path_info里?以后部分.事实上在这种情况下单篇文章页能够正常显示也仅仅因为有一个通过GET传递的 p变量,值为 18.html这样形式,然后php 的 (int) 或intval() 把它变成了18 = =

6 .关于Verbose rewrite
以Apache为例,wp默认生成的.htaccess里mod_rewrite规则非常简单:

  1. # BEGIN WordPress
  2. <IfModule mod_rewrite.c>
  3. RewriteEngine On
  4. RewriteBase /
  5. RewriteCond %{REQUEST_FILENAME} !-f
  6. RewriteCond %{REQUEST_FILENAME} !-d
  7. RewriteRule . /index.php [L]
  8. </IfModule>
  9. # END WordPress

复制代码

如 果当前请求不为文件或目录,把URL请求里第一个字符重写到index.php并停止继续rewrite.然后WP会通过request_uri或 path_info解析query vars, 如上面所述.  WP还提供一种non verbose rewrite rules, 但并没有提供前台接口. 在wp-include/rewrite.php里把WP_Rewrite里var $use_verbose_rules = true; 这句赋值改为false, 后台重新保存一下permalink,你会发现.htaccess里内容已经变了:

  1. # BEGIN WordPress
  2. <IfModule mod_rewrite.c>
  3. RewriteEngine On
  4. RewriteBase /
  5. RewriteCond %{REQUEST_FILENAME} -f [OR]
  6. RewriteCond %{REQUEST_FILENAME} -d
  7. RewriteRule ^robots\.txt$ /index.php?robots=1 [QSA,L]
  8. RewriteRule ^.*wp-atom.php$ /index.php?feed=atom [QSA,L]
  9. RewriteRule ^.*wp-rdf.php$ /index.php?feed=rdf [QSA,L]
  10. RewriteRule ^.*wp-rss.php$ /index.php?feed=rss [QSA,L]
  11. RewriteRule ^.*wp-rss2.php$ /index.php?feed=rss2 [QSA,L]
  12. RewriteRule ^.*wp-feed.php$ /index.php?feed=feed [QSA,L]
  13. RewriteRule ^.*wp-commentsrss2.php$ /index.php?feed=rss2&withcomments=1 [QSA,L]
  14. RewriteRule ^feed/(feed|rdf|rss|rss2|atom)/?$ /index.php?&feed=$1 [QSA,L]
  15. RewriteRule ^(feed|rdf|rss|rss2|atom)/?$ /index.php?&feed=$1 [QSA,L]
  16. …..
  17. RewriteRule ^(.+)/page/?([0-9]{1,})/?$ /index.php?pagename=$1&paged=$2 [QSA,L]
  18. RewriteRule ^(.+)/comment-page-([0-9]{1,})/?$ /index.php?pagename=$1&cpage=$2 [QSA,L]
  19. RewriteRule ^(.+)(/[0-9]+)?/?$ /index.php?pagename=$1&page=$2 [QSA,L]
  20. </IfModule>
  21. # END WordPress

你 可能对这种rewrite规则更为熟悉,国内的程序基本上都是用这种Rewrite. 请注意这时WP的内部过程完全不同. 在这种情况下, WP 的query vars值均来源于$_GET (Apache直接rewrite生成的), 但Request_uri或Path_Info仍会被解析并且生成的$perma_query_vars完全正确,! 只是不会被用于query vars而已. 因为$_GET优先级高于对url rewrite获得的值. 有人在windows下IIS的httpd.ini里加入rewrite规则,后台permalink设置为默认后rewrite后友好地址仍可以访问, 就是这个原因.

如果你能看懂(或早已知道)上面内容, 那么, 我相信对所有关于Wordpress rewrite/permalink方面的问题,你都能够解决,或者至少找到思路.至少,我是这样的.XT.

Bookmark and Share

WordPress教程:PHP文件编辑器

This item was filled under [ wordpress tips ]

使用WordPress,很多朋友都会在主题的选择上花大量的时间,我比较认可的一种方式是,选择一款主题,进行适当的修改。从这篇文章开始,我将 陆续介绍对WordPress主题进行修改需要的软件,并且对官方默认的主题进行分析,让大家能通过主题的修改,来完善自己的主题,达到满意的效果。这里需要强调一点,不管对主题修改到什么地步,只要主题不是原创的,请加上版权说明。
可以PHP文件编辑器很多,我介绍的,是基于我自己的使用。
我使用的PHP文件编辑器是Editplus,这个编辑器最大的特点是在编辑PHP文件并保存后,会生成一个针对未编辑前文件的备份文件,以.BAK结 尾。这样的好处是显而易见的,如果对PHP文件的修改失败,可以直接对备份进行还原,修改。EditPlu是一套功能强大,可取代记事本的文字编辑器,拥 有无限制的撤消与重做、自动换行、英文拼字检查、搜寻取代、列数标记、同时编辑多文件、全屏幕浏览功能。能够同步于剪贴板自动将文字粘贴进 EditPlus 的编辑窗口中,让你省去粘贴的步骤,而它还有一个好用的功能,就是它有监视剪贴板的功能!
还有很多的功能,可以在使用的过程中去了解,熟悉。软件已经发布第三个版本,我个人使用的是绿色版的。
绿色版地址链接:Editplus

绿色版下载地址失效了,可能是在调整,所以我还保留了链接地址,大家可以www.g.cn下载该软件。

Bookmark and Share
Page 1 of 512345»