1 回答

TA貢獻1785條經(jīng)驗 獲得超4個贊
您沒有正確格式化HTML/ table,因此為什么您在 WordPress 頁面上將所有內容打印在一行中。
您不需要分別回顯每一個td。您只需在您的variableto be和 中包裝一個定義,然后使用即可,并且只需將循環(huán)數(shù)據(jù)連接到該變量即可。echoedfunction
只需將其粘貼code到您的活動主題functions.php文件中,然后[tryin]在頁面中調用您的短代碼即可。(代碼經(jīng)過測試并且有效)
function trying_2() {
global $wpdb;
$results = '<table border="1">
<thead>
<tr>
<th>name</th>
<th>partysize</th>
<th>phonenumber</th>
<th>emailaddress</th>
<th>Time_stamp</th>
<th>currentstatus</th>
</tr>
</thead>
<tbody>';
// sending query
$WPQuery = $wpdb->get_results ("SELECT * FROM table_name");
foreach ( $WPQuery as $print ) {
$results .= "<tr>
<td>$print->name</td>
<td>$print->partysize</td>
<td>$print->phonenumber</td>
<td>$print->emailaddress</td>
<td>$print->Time_stamp</td>
<td>$print->currentstatus</td>
</tr>";
}
$results .= "</tbody>
</table>";
//Print results
echo $results;
}
add_shortcode('tryin', 'trying_2');
- 1 回答
- 0 關注
- 115 瀏覽
添加回答
舉報