在您的page.php文件在需要區域內循環添加該代碼。
替換$my_page_id
,$table_name
的值,並根據您的要求添加列。
<?php
$my_page_id = 111; // page ID here
if(get_the_ID() === $my_page_id) {
global $wpdb;
$table_name = 'your_table_name_here';
$myrows = $wpdb->get_results("SELECT column_1, column_2, column_3 FROM ". $table_name); // add columns as you want
?>
<table>
<thead>
<tr>
<th>Column 1</th>
<th>Column 2</th>
<th>Column 3</th>
</tr>
</thead>
<tbody>
<?php foreach ($myrows as $myrow) { ?>
<tr>
<td><?php echo $myrow->column_1; ?></td>
<td><?php echo $myrow->column_2; ?></td>
<td><?php echo $myrow->column_3; ?></td>
</tr>
<?php } ?>
</tbody>
</table>
<?php
}
嗨,Omair,對不起,如果我問一個愚蠢的問題;但這個page.php在哪裏?這是完全一樣的名字嗎?抱歉,我對WP非常陌生!假設你在page.php中創建了一個新項目?謝謝 – user385729
page.php位於:'/ wp-content/themes/{theme-name}/page.php'在你的web服務器上。以下是您可以如何找到頁面ID:http://goo.gl/QTdkPJ。我希望你知道你想要檢索的數據庫表名稱和列名:')' –
YEa我知道:D但是它是像PHP還是......我們需要通過數據庫配置,如主機,密碼,DBname?如果是這樣,我應該通過這些配置?你是非常有幫助的人。謝謝:) – user385729