实现所需功能的最佳方法是使用post\\u元/自定义字段。
add_shortcode (\'cities\', \'show_cities\');
function show_cities(){
/*
Create a custom field \'city\' to save city name in page editor
*/
$city = get_post_meta( get_the_id(), \'city\', true );
return $city;
}
使用数组还可以执行以下操作:
add_shortcode (\'cities\', \'show_cities\');
function show_cities(){
/*
Create an array using Page_id as index, e.g.
$cities [ \'page_id\' ] = "City Name";
*/
$cities [ 7 ] = "New York";
$cities [ 10 ] = "Alabama";
return $cities [ get_the_id() ];
}