您应该在函数中插入以下代码。主题的php。
/* Global matrix for shortcodes/content for every page */
$locations = array(
array(
\'location\' => \'location 1\',
\'telephone\' => \'0121 34838383\',
\'email\' => \'[email protected]\'
),
array(
\'location\' => \'location 2\',
\'telephone\' => \'92939393\',
\'email\' => \'[email protected]\'
),
array(
\'location\' => \'location 3\',
\'telephone\' => \'343443433\',
\'email\' => \'[email protected]\'
),
array(
\'location\' => \'location 4\',
\'telephone\' => \'343433\',
\'email\' => \'[email protected]\'
),
array(
\'location\' => \'Global Matrix Page\',
\'telephone\' => \'222 33 22\',
\'email\' => \'[email protected]\'
)
);
function telephone_shortcode() {
global $locations;
$title = get_the_title();
$key = array_search($title, array_column($locations, \'location\'));
if ($key)
return $locations[$key][\'telephone\'];
else
return \'\';
}
add_shortcode(\'telephone\', \'telephone_shortcode\');
function email_shortcode() {
global $locations;
$title = get_the_title();
$key = array_search($title, array_column($locations, \'location\'));
if ($key)
return $locations[$key][\'email\'];
else
return \'\';
}
add_shortcode(\'email\', \'email_shortcode\');
/* End of Global Matrix */
$位置数组包含您的位置(页面标题)、电话和电子邮件。您可以根据需要扩展它。
下面是定义页面上短代码的两个功能:[电话]和[电子邮件]。它们是相似的。每个函数获取当前页面的标题(get\\u the\\u title)并在$locations数组中查找它,然后返回相应的电话或电子邮件。
您的页面可以如下所示:
telephone = [telephone]
email = [email]
代码已测试,您可以看到结果
here.