submit to reddit Add to Technorati Favorites Stumble Upon Toolbar


sponsored link

Displaying wordpress posts to static HTML sites

If you've been given a task to make wordpress posts or content to display on a non wordpress site or to a static HTML site, you might be wondering how to do it.

Here is the solution i've found when i was once tasked to do it.

First is you need to make the extension of your static page where you want to display the posts to .php file (if it's not into php file yet).

Example: index.html to index.php

Then add this line of code to the top of your HTML code, should be before the <html> tag .


<?php
// Include WordPress
define('WP_USE_THEMES', false);
require('./wordpress/wp-load.php');
query_posts('showposts=1');
?>


Note: require() should be change to your own path of the wordpress loader.
Ex. your wordpress were inside of the folder called blog that is located in the root folder, then its should be
require('blog/wp-load.php');

And then lastly just put this code in the area where you want the posts to display


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

Your done.

source


Share/Save/Bookmark

Back to HOME

No comments: