0

这是国家插件中的代码,但我不知道如何以简写形式编写此代码,

  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 );

谁能告诉我应该写什么短代码才能在一页上显示所有国家/地区的名称?

4

1 回答 1

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 = ""] 
于 2013-03-07T16:07:08.450 回答