2013-03-07 61 views
0

的短码这是国家代码插件,但我不`吨知道如何以短格式编写的代码,我如何写WordPress插件

function save_details($post_id) { 
      global $post; 

      $post_vars = shortcode_atts(array(
       'country_code'  => '', 
       'country_list'  => '', 
       'flags'   => '', 
       'country_details' => '', 
       'country_currency' => '', 
       'currency_symbol' => '', 
       'currency_html' => '', 
       'currency_code' => '', 
       'city_list'  => '' 
      ), $_POST); 

任何人能告诉我是什么短码我应该写信给所有国家的名字在一个页面上?

回答

0

你可以重新写你的函数像这样

add_shortcode('save_details', function($atts) { 
     global $post; 

     $post_vars = array(
      'country_code'  => '', 
      'country_list'  => '', 
      'flags'   => '', 
      'country_details' => '', 
      'country_currency' => '', 
      'currency_symbol' => '', 
      'currency_html' => '', 
      'currency_code' => '', 
      'city_list'  => '' 
     ); 
     extract(shortcode_atts($post_vars, $atts)); 
     // country_code is now available like so $country_code 
     // return data after your done 

}); 

和访问它像这样

//all of your attributes can be used inside the sq brackets 
[save_details] and [save_details country_code = "" country_list = ""] 
+0

大卫追逐:我正在浇注的错误就是这样,语法错误,意外“add_shortcode”(T_STRING ),expect函数(T_FUNCTION) – 2013-03-08 03:57:10

+0

你可以发布你如何使用你的版本 – 2013-03-08 04:18:40

+0

这是一个插件url :: http://wordpress.org/extend/plugins/countries/,我使用的是wordpress 3.5.1,David i想要所有国家的名字,如果我点击英国,那么它显示所有的国家的国家,我点击状态,下一页显示所有的城市状态,你可以建议插件的 – 2013-03-08 09:43:46