Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I include Wordpress posts in a custom PHP file?

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?)

like image 420
Joernsn Avatar asked Jan 22 '23 09:01

Joernsn


1 Answers

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.

like image 95
Nicolò Martini Avatar answered Jan 29 '23 08:01

Nicolò Martini