我试图在超链接中使用一个短代码
<a class="wpb_button_a" title="Reserve Now" href="/reservation/?unitrate=[print_csv position="5"]&unitsize=5%20X%205&moveinoffer=[print_csv position="8"]"><span class="wpb_button wpb_btn-warning wpb_btn-large tocenter">Reserve Now</span></a>
当我使用上面的代码并发布它更改为的页面时
<a class="wpb_button_a" title="Reserve Now" href="/reservation/?unitrate=[print_csv position="><span class="wpb_button wpb_btn-warning wpb_btn-large tocenter">Reserve Now</span></a>
那些短代码只是普通文本没什么大不了的,对我来说结果应该是
<a class="wpb_button_a" title="Reserve Now" href="/reservation/?unitrate=60&unitsize=5%20X%205&moveinoffer=N/A"><span class="wpb_button wpb_btn-warning wpb_btn-large tocenter">Reserve Now</span></a>
如有任何帮助,敬请谅解
更新:这是我的短代码的总体代码
function _load_google_csv( $atts ) {
extract( shortcode_atts( array(
\'position\' => \'\',
), $atts ) );
ob_start();
// store spreadsheet content into variable
$data = file_get_contents(\'https://docs.google.com/spreadsheets/d/1oC88LWXn4SgvVzK3wQAojXk7UM5tDjuWuMZDAjQTGjw/pub?gid=0&single=true&output=csv\');
// Convert Comma separted String to Array
$data = explode(\',\', $data );
// Remove Comment to know the array position of the value you want to pull
#echo \'<pre>\', print_r( $data, 1), \'</pre>\';
/* The first two array value are like this,
[0] => 5X5
[1] => Only 1 Left
5X10
You see the second array value is "Only 1 Left (Newline) 5X10" and since you don\'t
want to pull 5X10, this can be remove from the string using str_replace function,
refer to http://www.w3schools.com/php/func_string_str_replace.asp, you may also want
to improve your CSV format to avoid using of str_replace
Doing it step by step
#get the second array value
$array_1 = $data[1] // Value of $array_1 is "Only 1 Left (Newline) 5X10"
# Remove "5X10" from $array_1 value using str_replace();
$desired_value = str_replace(\'5X10\', \'\', $array_1);
echo $desired_value; // $desired_value Will now output a value of "Only 1 Left"
*/
echo \'\', print_r( str_replace(\'5X10\', \'\', $data[$position]), 1), \'\';
return ob_get_clean();
}
add_shortcode(\'print_csv\',\'_load_google_csv\');
这样做的目的是从google sheets加载一个包含所有数据的csv。
传递到url中下一页的两条最重要的信息是价格、单位大小和报价。
这些片段保留在url中,并使用
echo $_GET[\'unitrate\'];
通过这样做,客户端可以简单地使用google sheets进行更改,以便在需要时更新信息。