I am using a php function to include a snippet of the latest post from my blog page (wordpress) on my home page, which is not wordpress. The actual code i am using is:
<?php
// Include WordPress
define('WP_USE_THEMES', false);
require('./fitness_blog/wp-load.php');
query_posts('showposts=1');
?>
<?php while (have_posts()): the_post(); ?>
<blockquote><h2><?php the_title(); ?></h2>
<a href="<?php the_permalink() ?>"><?php the_post_thumbnail( 'thumbnail', $attr ); ?> </a>
<p style="color:#3FF;"> <?php twentyten_posted_on(); ?> </p>
<?php the_excerpt(); ?>
<?php endwhile; ?>
I dont have any other php on the page anywhere…not even at the very top, in the header, etc. the url of the page is http://www.uniconutrition.com . When I remove this code from the page, it loads SOO much faster, so I know this is whats weighting it down. Any ideas? Thanks so much
WordPress isn’t a light weight and you’re loading the entire environment to display just a single post. You have a couple options to speed it up.
Manually query the database for the latest wordpress post without loading the wordpress environment.
Wrap all of that code in an output buffer and cache the post to a file with a timestamp. Check for the file and it’s timestamp on page load. If it’s not there or it’s older than say 5 or 10 minutes or however often you update your blog, load wordpress, render the post, and cache it to a file.
I would probably choose option 1 but either one would make a huge difference.
You should look at writing a plugin that adds an AJAX listener hook into WordPress. You can then send/receive a small JSON packet and get just what you need, leaving WordPress running on a separate thread.
There are a lot of examples on WordPress Codex on writing a simple AJAX listener plugin.