WordPress自定义帖子类型事件与自定义永久链接结构
问题描述:
我需要一些关于自定义链接的自定义帖子类型的帮助。WordPress自定义帖子类型事件与自定义永久链接结构
我创建了一个名为“evento”的自定义帖子类型和3个用于存储事件日期,月份和年份的自定义字段。
我想有一个永久链接结构是这样的:
/eventos/2012/07/30
...其中标准结构将是:
/?post_type=evento&ano=2012&mes=07&dia=30
如何使在WordPress这种神奇的发生呢?我不知道很多有关的.htaccess =(
在此先感谢!
答
这应该做你想要什么:
重写规则^ EVENTOS /([0-9] +)/([ 0-9] +)/([0-9] +)$ /?post_type =事件摘要& ANO = $ 1 & MES = $ 16 &直径= $ 3使用http://htaccess.madewithlove.be/
良好L]
我测试了它
答
问题解决!!!! =)
add_action('init', 'evento_add_rewrite_rules');
function evento_add_rewrite_rules($wp_rewrite){
// Add day archive (and pagination)
add_rewrite_rule("eventos/([0-9]{4})/([0-9]{2})/([0-9]{2})/page/?([0-9]{1,})/?",'index.php?post_type=evento&ano=$matches[1]&mes=$matches[2]&dia=$matches[3]&paged=$matches[4]','top');
add_rewrite_rule("eventos/([0-9]{4})/([0-9]{2})/([0-9]{2})/?",'index.php?post_type=evento&ano=$matches[1]&mes=$matches[2]&dia=$matches[3]','top');
// Add month archive (and pagination)
add_rewrite_rule("eventos/([0-9]{4})/([0-9]{2})/page/?([0-9]{1,})/?",'index.php?post_type=evento&ano=$matches[1]&mes=$matches[2]&paged=$matches[3]','top');
add_rewrite_rule("eventos/([0-9]{4})/([0-9]{2})/?",'index.php?post_type=evento&ano=$matches[1]&mes=$matches[2]','top');
// Add year archive (and pagination)
add_rewrite_rule("eventos/([0-9]{4})/page/?([0-9]{1,})/?",'index.php?post_type=evento&ano=$matches[1]&paged=$matches[2]','top');
add_rewrite_rule("eventos/([0-9]{4})/?",'index.php?post_type=evento&ano=$matches[1]','top');
}
谢谢!