我有一个不同位置的多站点。我们必须创建一个自定义区域来放置标题和元信息。现在,标题仅输出在主题选项中设置的公司名称的短代码。我们必须为城市和州提供其他短信码。我更新了标题区域的代码,但它只适用于状态的最后一行代码。我需要所有三个代码才能工作。
**if($get_location['option_value'] == get_bloginfo('name'))
{
# grab title tag from page ID
$get_title = mysql_fetch_array(mysql_query('SELECT meta_value FROM wp_'.$number.'_postmeta WHERE meta_key = \'title\' AND post_id = \''.$post->ID.'\''));
# grab company name
$get_company_result = mysql_fetch_array(mysql_query('SELECT option_value FROM '.$td[0].' WHERE option_name = \'option_tree\''));
$get_city_result = mysql_fetch_array(mysql_query('SELECT option_value FROM '.$td[0].' WHERE option_name = \'option_tree\''));
$get_state_result = mysql_fetch_array(mysql_query('SELECT option_value FROM '.$td[0].' WHERE option_name = \'option_tree\''));
# clearn up returned value
$company = unserialize($get_company_result['option_value']);
$city = unserialize($get_city_result['option_value']);
$state = unserialize($get_state_result['option_value']);
# replace shortcode with company name
$return_title = str_replace('[company_name]',$company['company_name'], $get_title['meta_value']);
# replace shortcode with company name
$return_title = str_replace('[city]',$city['city'], $get_title['meta_value']);
# replace shortcode with company name
$return_title = str_replace('[state]',$state['state'], $get_title['meta_value']);
# if values are not empty/null
if($get_title['meta_value'] != '' or $get_title['meta_value'] != NULL)
{
$title = $return_title;
}**
答案 0 :(得分:0)
您要更新相同的变量$return_title
3次。请改用此代码:
$return_title = $get_title['meta_value']; //put into a variable
# replace shortcode with company name
$return_title = str_replace('[company_name]',$company['company_name'], $return_title); //override variable with str_replace
# replace shortcode with company name
$return_title = str_replace('[city]',$city['city'], $return_title); //override variable with str_replace
# replace shortcode with company name
$return_title = str_replace('[state]',$state['state'], $return_title); //override variable with str_replace