在 wordpress 安装目录之外加载 wordpress 博客文章 [英] Load wordpress blog posts outside wordpress installation directory
本文介绍了在 wordpress 安装目录之外加载 wordpress 博客文章的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
是否可以只加载wordpress安装目录之外的部分内容?我在一个网站上工作,我想在使用 bootstrap4 制作的静态 index.php
上嵌入一些博客内容.此页面不是 wordpress 安装的一部分,所以我想了解这是否可行以及如何实现.
Is it possible to load only some contents outside the wordpress installation directory? I'm working on a website and I want to embed some blog contents on a static index.php
made using bootstrap4. This page is not part of the wordpress installation, so I want to understand if this is possible and how.
推荐答案
试试这个:
注意:将 'path-to-wordpress' 更改为实际的 wp 目录路径.
Note: change the 'path-to-wordpress' to actual wp directory path.
define('WP_USE_THEMES', FALSE);
require('/path-to-wordpress/wp-load.php');
$args = array(
'posts_per_page' => 5 // Specify how many posts you'd like to display
);
$latest_posts = new WP_Query( $args );
if ( $latest_posts->have_posts() ) {
while ( $latest_posts->have_posts() ) {
$latest_posts->the_post(); ?>
<li>
<a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a>
<?php the_excerpt(); ?>
</li>
<?php }
}
else {
echo '<p>There are no posts</p>';
}
wp_reset_postdata();
wp_reset_query();
这篇关于在 wordpress 安装目录之外加载 wordpress 博客文章的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文