如何在我的html网站上添加wordpress帖子,博客位于myurl.com/blog

时间:2018-06-07 20:43:03

标签: php wordpress integration blogs

如何将wordpress帖子添加到我的html网站中,博客位于myurl.com/blog我已经在线查看,但我没有看到任何全面的教程。所以我希望能够在我的网站上有一个部分来获取wordpress页面上的帖子,任何帮助都会非常感激。谢谢。

1 个答案:

答案 0 :(得分:0)

最简单的方法是在WordPress Codex中:Integrating WordPress with Your Website « WordPress Codex

它没有变得更简单。在你的html网站的index.html文件的标题中调用wp-blog-header.php文件。

<?php 
define('WP_USE_THEMES', false);
require('./wp-blog-header.php');
?>

然后使用标准循环在要显示帖子的页面上加载帖子:

<?php
require('/the/path/to/your/wp-blog-header.php');
?>

<?php
$posts = get_posts('numberposts=10&order=ASC&orderby=post_title');
foreach ($posts as $post) : setup_postdata( $post ); ?>
<?php the_date(); echo "<br />"; ?>
<?php the_title(); ?>    
<?php the_excerpt(); ?> 
<?php
endforeach;
?>

<强>更新

要确定您的服务器上是否正在运行PHP,请使用FTP上传名为phpinfo.php的纯文本文件,其中只包含此行,并且文件顶部没有空格:

<?php phpinfo(); ?>

然后转到yoursite.com/phpinfo.php - 或yoursite.com/somefolder/phpinfo.php,您应该看到一大堆PHP配置。如果你不这样做,PHP就没有运行。向GoDaddy询问一下。