效果如下:
当你的内容标题为 绿色软件 时,链接地址里将带上 lvseruanjian .
实现过程:
然后就可以在url规则里使用 {$pinyin} 这个url标志了.注意是内容规则(show),不适用栏目url.
当你的内容标题为 绿色软件 时,链接地址里将带上 lvseruanjian .
实现过程:
修改 modules/content/classes/url.class.php 文件的 public function show() 函数为如下代码:
public function show($id, $page = 0, $catid = 0, $time = 0, $prefix = '',$data = '',$action = 'edit') {
$page = max($page,1);
$urls = $catdir = '';
$category = $this->categorys[$catid];
$setting = string2array($category['setting']);
$content_ishtml = $setting['content_ishtml'];
$show_ruleid = $setting['show_ruleid'];
$urlrules = $this->urlrules[$show_ruleid];
if(!$time) $time = SYS_TIME;
$urlrules_arr = explode('|',$urlrules);
if($page==1) {
$urlrule = $urlrules_arr[0];
} else {
$urlrule = $urlrules_arr[1];
}
if (strpos($category['url'], '://')!==false && strpos($category['url'], '?')===false) {
if (preg_match('/^((http|https):\/\/)?([^\/]+)/i', $category['url'], $matches)) {
$url = $matches[0].'/';
}
$db = pc_base::load_model('category_model');
$r = $db->get_one(array('url'=>$url), '`catid`');
$domain_dir = $this->get_categorydir($r['catid']).$this->categorys[$r['catid']]['catdir'].'/';
}
$categorydir = $this->get_categorydir($catid);
$catdir = $category['catdir'];
$year = date('Y',$time);
$month = date('m',$time);
$day = date('d',$time);
//add 开始
pc_base::load_sys_func('iconv');
$modelid = $category['modelid'];
if(!$modelid) return '';
$db = pc_base::load_model('content_model');
$db->set_model($modelid);
$r = $db->get_one(array('id'=>$id), '`title`');
$pinyin = gbk_to_pinyin($r['title']);
if(is_array($pinyin)) {
$pinyin = implode('', $pinyin);
}
//end 结束
$urls = str_replace(array('{$categorydir}','{$catdir}','{$year}','{$month}','{$day}','{$catid}','{$id}','{$page}','{$pinyin}'),array($categorydir,$catdir,$year,$month,$day,$catid,$id,$page,$pinyin),$urlrule);
$create_to_html_root = $category['create_to_html_root'];
if(preg_match("/^(http:\/\/)?([^\/]+)/i", $category['url'],$_match)) {
if($category['parentid'] && $_match[0]) {
foreach ($this->categorys as $_key=>$_value) {
if($_value['create_to_html_root'] && $_value['url']==$_match[0].'/') $create_to_html_root = 1;
}
}
}
if($create_to_html_root) {
$html_root = '';
} else {
$html_root = $this->html_root;
}
if($content_ishtml && $url) {
if (strpos($urls, $domain_dir)!==false) {
$url_arr[1] = $html_root.'/'.$urls;
$url_arr[0] = str_replace($domain_dir, $url, $urls);
} else {
$url_arr[1] = $html_root.'/'.$domain_dir.$urls;
$url_arr[0] = WEB_PATH == '/' ? $url.$urls : substr(WEB_PATH,0,-1).$url.$urls;
}
} elseif($content_ishtml) {
$url_arr[0] = WEB_PATH == '/' ? $html_root.'/'.$urls : substr(WEB_PATH,0,-1).$html_root.'/'.$urls;
$url_arr[1] = $html_root.'/'.$urls;
} else {
$url_arr[0] = $url_arr[1] = APP_PATH.$urls;
}
//生成静态 ,在添加文章的时候,同时生成静态,不在批量更新URL处调用
if($content_ishtml && $data) {
$html = pc_base::load_app_class('html', 'content');
$data['id'] = $id;
$html->show($url_arr[1],$data);
//在添加和修改内容处定义了 INDEX_HTML
if(defined('INDEX_HTML')) $html->index();
if(defined('RELATION_HTML')) $html->create_relation_html($catid);
}
return $url_arr;
}
然后就可以在url规则里使用 {$pinyin} 这个url标志了.注意是内容规则(show),不适用栏目url.