How can I include Wordpress posts in a custom PHP

2019-03-21 10:59发布

This is what i want to do:

I want /summary.php to include 5 latest posts (only the extract) from my blog, which lives in /wp.

Is there any way to include Wordpress in /summary.php and only print the html for these posts? (Maybe i should parse the rss?)

5条回答
劫难
2楼-- · 2019-03-21 11:12

You can create a "clean" template, which you can apply to 'summary' page (this page must be a wordpress page too). You can find an example here: http://www.tyssendesign.com.au/articles/cms/fetching-posts-in-wordpress-expressionengine-with-jquery-ajax/

查看更多
霸刀☆藐视天下
3楼-- · 2019-03-21 11:17

Take a look to Integrating WordPress with your Website

This is an example from that page, that shows the first ten posts in alphabetical order:

<?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) : start_wp(); ?>
<?php the_date(); echo "<br />"; ?>
<?php the_title(); ?>    
<?php the_excerpt(); ?> 
<?php
endforeach;
?>

Use $posts = get_posts('numberposts=10'); if you want the 10 latest posts.

查看更多
时光不老,我们不散
4楼-- · 2019-03-21 11:19

you can include wp-config.php, which will pull in the rest of the API. then you will be able to use wp functions like

function get_post($postID)
查看更多
地球回转人心会变
5楼-- · 2019-03-21 11:33

Probably the easiest and most elegant way to do this is to create a custom theme to live on summary.php. The WP library exposes a number of functions for easy output of articles.

查看更多
Emotional °昔
6楼-- · 2019-03-21 11:35

I think you have answered your self their. The RSS feed will give you the content of your latest posts.

With not much work you can just pull out the data you need

查看更多
登录 后发表回答