【发布时间】:2019-11-19 00:56:59
【问题描述】:
我正在尝试创建一个 wordpress 网站,其中包含页面上的一些信息,并显示来自数据库的数据。所以,我有一些要显示的信息的主页。我想在主页上的此信息下方显示数据。所以,我执行了以下步骤:
1) Created a block on the new page and enter the information for the home page
2) Inserted data on the database
3) Created a publications.php page and saved it on the themes folder as Publication template
4) Installed InsertPages plugin on wordpress
5) Created a new page with title and template set as Publication
6) Then, added a new block below the block from 1) in the Home page
代码如下所示:
<?php
/**
* Template Name: Publications
* The template used for displaying publications
*/
?>
<div class="pubications">
<ul class="collection">
<?php
global $wpdb;
$publications = $wpdb->get_results("SELECT * FROM `cidhi_publications` ORDER by Year DESC LIMIT 12;");
<div class="content">
foreach($publications as $publication){
echo "<li class='collection-item avatar'><a href='https://doi.org/".$publication->doi."'>";
echo "<img src='/cidhi/wp-content/uploads/2019/11/".$publication->image_name."' alt='' class='circle'>";
echo "<span class='title'>".$publication->Title."</span>";
echo "<p>".$publication->Authors."</p>";
echo "<a href='#!' class='secondary-content'>".$publication->Year."</a>";
echo "</a></li>";
}
</div>
?>
</ul>
</div>
如果我只打开如下页面:http://localhost://wp/publications,它会显示数据但没有主题格式,而只是纯 HTML。
但是,如果我打开主页,该页面插入主页,我只看到标题而不是内容。我还检查了“InsertPages”插件中的设置,并确保“显示”部分选择了“全部”
这是我第一次使用 wordpress,所以任何方向都会很有帮助。我正在使用最新版本的 wordpress
【问题讨论】: