How to include Wordpress posts in a custom PHP file?

This is what I want to do:

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

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

+4
source share
5 answers

Take a look at WordPress Integration with your website

This is an example from this page that shows the first ten entries 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 to receive the last 10 messages.

+9
source

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

0
source

I think you answered your own. The RSS feed will provide you with the content of your latest posts.

With a little work, you can just pull out the data you need.

0
source

You can create a clean template that you can apply to the summary page (this page should also be a Wordpress page). Here you can find an example: http://www.tyssendesign.com.au/articles/cms/fetching-posts-in-wordpress-expressionengine-with-jquery-ajax/

0
source

you can enable wp-config.php which will pull the rest of the API. then you can use wp functions like

 function get_post($postID) 
0
source

Source: https://habr.com/ru/post/1305097/


All Articles