在您的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