I have client that built a website that is part static html and part Wordpress. The Wordpress is only for the blog while the static pages are for the rest of the site content, including the home page.
This same client would like to be able to "pull" recent blog posts and comment counts开发者_C百科 from the blog and post them on the home page.
I am not familiar with Wordpress, so I am posting this question to find out if this is even possible. If it is, I will naturally want to know "how?" but this is to get the ball rolling.
Any constructive feedback is welcome. Thanks!
If you're on a remote server, you could use WordPress's built-in RSS or XMLRPC interfaces.
If you're on the same server, this snippet is tested against WP 2.7 but will probably work in 3.0 as well
<?php
$number = 5;
$wordpress_header = "/path/to/wordpress/wp-blog-header.php";
// Include wordpress header
if (file_exists($wordpress_header))
{
include ($wordpress_header);
$myposts = get_posts('numberposts=$number&offset=0&category=0');
echo "<ul class='Bloglinks'>";
foreach(array_slice($myposts, 0, $number) as $post)
{
echo '<li><a href="';
the_permalink();
echo '">';
the_date();
echo " ";
the_title();
echo '</a></li>';
}
echo "</ul>";
}
else
{
echo "Unable to connect to Wordpress header file.";
die();
}
?>
Sure you can fetch whatever you want from the wp database. There is a table posts with all the posts in it. Just connect thru it like you would any other database and query away!
精彩评论