【发布时间】:2011-07-06 03:47:43
【问题描述】:
我的问题:
My permalink settings:
常规设置> 自定义 > /%postname%.html
可选设置>标签库>标签
我想要这个:mysite.com/%tag-slug%.html
谢谢
为@Dimitry 编辑
正是我想要的方式
<?php
/*
Plugin Name: Custom tag URLs
Description: Appends .html to tag links
*/
// applied when calling get_tag_link()
add_filter('tag_link', 'my_tag_link', 10, 2);
/**
* Returns a link to a tag. Instead of /tag/tag-name/ returns /tag-name.html
*/
function my_tag_link($tag_link, $tag_id) {
$tag_base = get_option('tag_base');
if ($tag_base) {
// problem. returning: http://www.domain.com/post-tag/tag-name
//$tag_link = preg_replace('@^' . preg_quote($tag_base, '@') . '@', '', $tag_link);
// I added it. Result: http://www.domain.com/tag-name
$tag_link = str_replace("$tag_base/", "", preg_replace('@^' . preg_quote($tag_base, '@') . '@', '', $tag_link));
//echo "$tag_link<br>";
}
// problem. returning: http://www.domain.com/http://www.domain.com/tag-name.html
//return '/' . trim($tag_link, '/') . '.html';
// I added it. Result: http://www.domain.com/tag-name.html ,
return trim($tag_link, '/') . '.html';
}
?>
我做了永久链接设置
常规设置> 自定义 > /post-%postname%.html 可选设置>标签库>后标签
.htaccess:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
# Rewrites /tag-name.html as /post-tag/tag-name
# Assuming that your tag_base option is blank or set to 'post-tag'
RewriteCond %{REQUEST_URI} !^/post-.*
RewriteRule ^/?([^/]*)\.html$ /post-tag/$1
单页:http://www.domain.com/post-hello-world.html >> 正在工作 标签页:http://www.domain.com/tag-name.html >> 未找到 404 http://www.domain.com/post-tag/tag-name >> 工作中
问题:
找不到标签页
对不起。我是初学者。谢谢迪米特里
【问题讨论】:
-
我猜一个 wordpress 论坛会带来更好的结果......这个问题可能有点过于本地化,而不是严格意义上的编程问题。
-
所以您希望您的帖子被他们的标签 + .html 引用?还是您希望标签以“.html”结尾?
-
我想要这个东西;标签页面网址:mysite.com/tag-slug.html 发布页面网址:mysite.com/post-slug.html 谢谢
标签: php wordpress mod-rewrite permalinks