2017-09-16 38 views
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');

回答

0

哎呀,我發現了錯誤... 當讀取數組中: 回報$ PriceListArray [$的ATT [ '列'] [$的ATT [ '行'] ;

屬性的順序應該行,然後列,而不是相反..

我想刪除的問題,但無法弄清楚這是否可能....