问题
What is the easiest way to display articles entries posted on a wordpress site (from a particular category) onto another non-wordpress site that is built in PHP/MySQL.
I understand wordpress uses MySQL so in theory I could connect via PHP to the database and pull the content directly if I can figure out the schema used
I know I can get an RSS feed - is there a parser available that I could use to get all article content including images etc?
回答1:
Wordpress content on non-Wordpress pages in same domain
This is a very database-intensive method as it loads almost the entirety of Wordpress behind the scenes, but it's easy and well-documented:
Display Wordpress content outside of your blog
This assumes that the Wordpress blog is on the same server as the non-Wordpress content and you can reference wp-load.php
Wordpress content on non-Wordpress pages on remote domain
One of the simplest simplest methods to syndicate content onto a remote domain is to parse the RSS feed using MagpieRSS.
There are a large number of code samples available:
- http://magpierss.sourceforge.net/links.shtml
- http://www.technologytricks.com/rss-read-php-magpierss/
- http://www.oneandoneis2.org/MagpieHowTo.php
To get the RSS feed for a particular category, use something like
http://www.example.com/?cat=42&feed=rss2
http://example.com/category/categoryname/feed
More here:
- Wordpress Feeds | WordPress Codex
回答2:
If the other pages are located on the same server you can do this by loading the wp-load.php file
First add this to the top of the page to load wp-load.php
<?php
// Include WordPress
define('WP_USE_THEMES', false);
require('./wordpress/wp-load.php');
query_posts('showposts=1');
?>
Then you can loop all the content via:
<?php while (have_posts()): the_post(); ?>
<h2><?php the_title(); ?></h2>
<?php the_excerpt(); ?>
<p><a href="<?php the_permalink(); ?>">Read more...</a></p>
<?php endwhile; ?>
Checkout this link: The Loop (Wordpress Codex)
来源:https://stackoverflow.com/questions/5387336/displaying-articles-from-a-wordpress-site-on-a-non-wordpress-site