我正在为想要将WordPress用于博客部分的朋友 Build 一个网站 . 我本来可以把整个网站作为一个自定义的WordPress主题,但我不喜欢使用WordPress,因为它是臃肿,缓慢和错误 . 因此,我希望通过包含WordPress站点中的wp-load.php文件并使用它们的功能,将最近的帖子模块添加到站点 .
我已经多次尝试创建模块,每种方法都会导致错误 .
使用 while (have_posts()) 循环导致 500 Internal Server Error 所以我尝试使用 wp_get_recent_posts(array 后跟 foreach 语句,这不会导致错误,而是让我得到 "End of file seen and there were open elements."
这是该网站的链接:http://colinthompson.ca/drake/
以下是该部分的代码:
<section id="blog">
<h3>recent posts</h3>
<div id="post-wrap">
<?php
$recent_posts = wp_get_recent_posts(array(
'numberposts' => 3
));
foreach ($recent_posts as $post) {
echo '<div class="blog-post">
<div class="post-img">'.get_the_thumbnail($post['ID']).'</div>
<h5><a href="'.get_permalink($post['ID']).'" title="read whole article">'.$post['post_title'].'</a></h5>
<p>by <span>'.the_author($post['ID']).'</span></p>
<p>'.the_date(d,m,y).'</p>
<p>'.the_excerpt($post['ID']).'</p>
</div>';
}
?>
</div>
<a id="full-blog" href="#" title="Check out the full blog"><div class="slide-in"><p>full blog</p></div><div class="arrow-shaft"></div><div class="arrow-head"></div><p>read more</p></a>
<a class="next-section" href="#contact" title="Let's get in touch"><div class="slide-in"></div><div class="arrow-shaft"></div><div class="arrow-head"></div></a>
</section>
我尝试删除foreach语句来测试正在回显的html中未关闭的元素,但错误仍然存在,导致父 div#post-wrap 和祖父母 section#blog 的 unclosing 以及文档其余部分的一般捏造 .
当我 removed the wp_get_recent_posts 数组页面加载为 normal ,但当然没有帖子 .
也许我只是忘了逃避一些事情,但我没有看到它 . 任何帮助表示赞赏 .
谢谢!
1 回答
你要在哪里展示这些帖子?你的朋友要去哪儿写?
在我看来,你最好只在网站的一个部分包含WordPress .