0
我正在嘗試編寫一個WP短代碼來讀取組織爲2維數組的價目表。短缺有2個屬性 - 列和行 - 應該價目表陣列使用WP shorcode讀取數組
與下面的守則草案在列/線位置歸還號碼,短碼從數組返回看似隨機值...
但是,當我插入實際整數而不是$ atts ['column']和$ atts ['line']時,所有工作和shortocde都會從數組中返回正確的值。任何想法 ?
// Add Shortcode
function price_shortcode($atts) {
\t // Attributes
\t $atts = shortcode_atts(
\t \t array(
\t \t \t 'column' => '',
\t \t \t 'line' => '',
\t \t),
\t \t $atts,
\t \t 'price'
\t);
\t // Return content of price list at specified location
\t ini_set("auto_detect_line_endings", true);
\t
\t $PriceListArray = array();
\t if (($handle = fopen("wp-content/themes/twentythirteen-child/pa/PriceList.csv", "r")) !== FALSE) {
\t while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {
\t $PriceListArray[] = $data;
\t }
\t fclose($handle);
\t }
\t
\t ini_set("auto_detect_line_endings", false);
\t
\t
\t return $PriceListArray[$atts['column']][$atts['line']];
\t
\t
}
add_shortcode('price', 'price_shortcode');