[英]Issue with permalinks for non-latin characters in the URL
我正在使用osclass平台,並且嘗試將類別標簽的非拉丁字符轉換為拉丁語,但是我無法使其正常工作。 這是我到目前為止所做的:
在幫助文件hDefines.php中,我修改了如下代碼:
function osc_item_url_from_item($item, $locale = '')
{
if ( osc_rewrite_enabled() ) {
$url = osc_get_preference('rewrite_item_url');
if( preg_match('|{CATEGORIES}|', $url) ) {
$sanitized_categories = array();
$cat = Category::newInstance()->hierarchy($item['fk_i_category_id']);
for ($i = (count($cat)); $i > 0; $i--) {
$sanitized_categories[] = $cat[$i - 1]['s_slug'];
}
$url = str_replace('{CATEGORIES}', implode("/",
cust_gr_to_latin_cats($sanitized_categories)), $url);
}
$url = str_replace('{ITEM_ID}', osc_sanitizeString($item['pk_i_id']), $url);
$url = str_replace('{ITEM_CITY}', osc_sanitizeString($item['s_city']), $url);
$url = str_replace('{ITEM_TITLE}', osc_sanitizeString(cust_greek_to_latin($item['s_title'])), $url);
$url = str_replace('?', '', $url);
if($locale!='') {
$path = osc_base_url().$locale."/".$url;
} else {
$path = osc_base_url().$url;
}
} else {
$path = osc_item_url_ns($item['pk_i_id'], $locale);
}
return $path;
}
在我的自定義主題functions.php文件中,我添加了以下功能:
function cust_gr_to_latin_cats($catsgr) {
$grcats = array('ά','α','Α','Ά','β','Β','γ','Γ','δ','Δ','ε','έ','Ε','Έ','ζ','Ζ','η','ή','Ή','Η','ί','ι','Ί','Ι','κ','Κ','λ','Λ','μ','Μ','ν','Ν','ξ','Ξ','ο','ό','Ό','Ο','π','Π','ρ','Ρ','σ','Σ','ς','τ','Τ','ύ','υ','Υ','Ύ','φ','Φ','χ','Χ','ψ','Ψ','ω','ω','Ω','Ώ','θ','Θ' );
$latr = array('a','a','a','a','v','v','g','g','d','d','e','e','e','e','z','z','h','h','h','h','i','i','i','i','k','k','l','l','m','m','n','n','x','x','o','o','o','o','p','p','r','r','s','s','s','t','t','y','y','y','y','f','f','ch','ch','ps','ps','w','w','w','w','th','th' );
return str_replace($grcats, $latr, $catsgr);
}
我在做什么錯???
您可以這樣嘗試:
function osc_item_url_from_item($item, $locale = '')
{
if ( osc_rewrite_enabled() ) {
$url = osc_get_preference('rewrite_item_url');
if( preg_match('|{CATEGORIES}|', $url) ) {
$sanitized_categories = array();
$cat = Category::newInstance()->hierarchy($item['fk_i_category_id']);
for ($i = (count($cat)); $i > 0; $i--) {
$sanitized_categories[] = cust_greek_to_latin($cat[$i - 1]['s_slug']);
}
$url = str_replace('{CATEGORIES}', implode("/",$sanitized_categories), $url);
}
$url = str_replace('{ITEM_ID}', osc_sanitizeString($item['pk_i_id']), $url);
$url = str_replace('{ITEM_CITY}', osc_sanitizeString($item['s_city']), $url);
$url = str_replace('{ITEM_TITLE}', osc_sanitizeString(cust_greek_to_latin($item['s_title'])), $url);
$url = str_replace('?', '', $url);
if($locale!='') {
$path = osc_base_url().$locale."/".$url;
} else {
$path = osc_base_url().$url;
}
} else {
$path = osc_item_url_ns($item['pk_i_id'], $locale);
}
return $path;
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.