我已经成功地在函数中为我的wordpress站点编码了一个辅助数据库连接。wordpress中的php文件。我使用以下方法创建了短代码,并将数据运行到我的表中,通过粘贴短代码,我可以将数据显示在网站的任何位置。我在第313行遇到以下错误,我不明白它告诉我要修复什么。
分析错误:语法错误,在/home/g3boat5/genba中出现意外的“开始”(T\\U字符串)。g3boatco。信息/wp内容/主题/二十一/功能。php在线313
// add the shortcode [pontoon-table], tell WP which function to call
add_shortcode( \'pontoon-table\', \'pontoon_table_shortcode\' );
// this function generates the shortcode output
function pontoon_table_shortcode( $args ) {
global $wpdb;
// Shortcodes RETURN content, so store in a variable to return
$content = \'<table>\';
$content .= \'</tr><th>Week Beginning</th><th>Monday</th><th>Tuesday</th><th>Wednesday</th><th>Thursday</th><th>Friday</th><th>Saturday</th><th>Sunday</th><th>Weekly Total</th><th>Previosu Week Total</th></tr>\';
$results = $wpdb->get_results( \' SELECT * FROM wpdb_PontoonBoats_LineOne_2Log\' );
foreach ( $results AS $row ) {
$content = \'<tr>\';
// Modify these to match the database structure
$content .= \'<td>\' . $row->Week Beginning . \'</td>\';
$content .= \'<td>\' . $row->Monday . \'</td>\';
$content .= \'<td>\' . $row->Tuesday . \'</td>\';
$content .= \'<td>\' . $row->Wednesday . \'</td>\';
$content .= \'<td>\' . $row->Thursday . \'</td>\';
$content .= \'<td>\' . $row->Friday . \'</td>\';
$content .= \'<td>\' . $row->Saturday . \'</td>\';
$content .= \'<td>\' . $row->Sunday . \'</td>\';
$content .= \'<td>\' . $row->Weekly Total . \'</td>\';
$content .= \'<td>\' . $row->Previous Week Totals . \'</td>\';
$content .= \'</tr>\';
}
$content .= \'</table>\';
// return the table
return $content;
}
313号线就是这个
$content .= \'<td>\' . $row->Week Beginning . \'</td>\';
我不确定我对这段代码做了什么错事,使它对我不起作用。有人能帮我了解需要修复的问题吗?非常感谢。
最合适的回答,由SO网友:sMyles 整理而成
虽然在对象名称中使用空格是非常糟糕的做法,但有时它可能会超出您的控制。您可以使用$object->{\'Property Name\'}
, 像这样:
// add the shortcode [pontoon-table], tell WP which function to call
add_shortcode( \'pontoon-table\', \'pontoon_table_shortcode\' );
// this function generates the shortcode output
function pontoon_table_shortcode( $args ) {
global $wpdb;
// Shortcodes RETURN content, so store in a variable to return
$content = \'<table>\';
$content .= \'</tr><th>Week Beginning</th><th>Monday</th><th>Tuesday</th><th>Wednesday</th><th>Thursday</th><th>Friday</th><th>Saturday</th><th>Sunday</th><th>Weekly Total</th><th>Previosu Week Total</th></tr>\';
$results = $wpdb->get_results( \' SELECT * FROM wpdb_PontoonBoats_LineOne_2Log\' );
foreach ( $results AS $row ) {
$content .= \'<tr>\';
// Modify these to match the database structure
$content .= \'<td>\' . $row->{\'Week Beginning\'} . \'</td>\';
$content .= \'<td>\' . $row->Monday . \'</td>\';
$content .= \'<td>\' . $row->Tuesday . \'</td>\';
$content .= \'<td>\' . $row->Wednesday . \'</td>\';
$content .= \'<td>\' . $row->Thursday . \'</td>\';
$content .= \'<td>\' . $row->Friday . \'</td>\';
$content .= \'<td>\' . $row->Saturday . \'</td>\';
$content .= \'<td>\' . $row->Sunday . \'</td>\';
$content .= \'<td>\' . $row->{\'Weekly Total\'} . \'</td>\';
$content .= \'<td>\' . $row->{\'Previous Week Totals\'} . \'</td>\';
$content .= \'</tr>\';
}
$content .= \'</table>\';
// return the table
return $content;
}
UPDATE:
看起来你有
$content = \'<tr>\';
它重置字符串而不是附加到字符串,将其更改为
$content .= \'<tr>\';