Displaying Wordpress Posts in HTML page
How to display WordPress Posts on a standard Website...
We have created this useful guide to help fellow web developers provide a little more functionality to a website. Web designers and developers know that WordPress is built-in server-side technology called PHP and it's very difficult to place PHP into a standard HTML page.
The only way to do this in the past was to use third party RSS Aggregators like SimplePie and MagPie to fetch your latest posts from your blog’s RSS feed. This could mean a lot more scripts and code than you actually need. So we would like to share some useful code to help develop your site.
Step 1. - (Apache Server) - How to inject PHP into an HTML page
First you need to tell your webserver to allow PHP into an HTML file. Copy and paste this code into your htaccess file. (if you don't know what you're doing with htaccess files please be careful).
<br>AddHandler application/x-httpd-php .html<br>
Step 2 - PHP Script
<br><pre class="brush: php; title: ; notranslate" title=""><ul>
<?php require($_SERVER['DOCUMENT_ROOT'] . '/folder/wp-load.php'); query_posts('showposts=3'); if (have_posts()) : while (have_posts()) : the_post(); ?>
<li> <h2><a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a></h2>
<span>Posted on <?php the_time('l jS F, Y') ?></span>
<?php the_excerpt(); ?> </li>
<?php endwhile; else: echo "no posts"; endif; ?>
<?php wp_reset_query(); ?>
Step 3 Installation to HTML (Non Wordpress page)
- Copy the code above, and paste it onto your HTML web page.
- Adjust the path to wp-load.php on line 2. You will need to change this to match the name of your folder.
- Select how many posts you would like to feed through. If anything other than 3, simply locate ‘showposts=3′ on line 2, and adjust accordingly.
- Upload the HTML file and then the test file.
- Adjust the surrounding HTML as necessary.