【发布时间】:2017-09-20 23:26:54
【问题描述】:
我正在使用 osclass 平台,我正在尝试将类别 slug 的非拉丁字符转换为拉丁语,但我无法使其工作。这是我到目前为止所做的:
在帮助文件 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);
}
我做错了什么???
【问题讨论】: