I really wanted to incorporate this blog into my company website, so I went to searching, editing, and testing and got it to load the newest post into my website. I found a great website that helped me out, and that combined with a little playing around got it done quite quickly. The basic idea is you load in some PHP on your existing website, one part to tell the page to load the post (or posts) you want to show, and one part to tell the page where to load the post.
The Steps
BACKUP FIRST – If you have the files locally, make a quick copy of the whole directory in case you mess-up.
1) Server Directory locations – It works easiest if your WordPress blog is actually within your website directory (ill use fake directories for the example, but you will need to change it to your own.)
ie: on the server you have your website folder and inside that you put your WordPress blog
/website_folder/wordpress_folder
Note: I had to move my wordpress_folder into my website directory as I had it on the root of the server before this, I then had to change the subdomain destination to the new place I had moved the wordpress_folder
2) After that’s done, you need to change the desired_page.html into desired_page.php. (this is the page you want to add the blog posts into, if its already a .php name then skip the renaming parts.)
3) Then add this code to the very top of your desired_page.php
<?php
// Include WordPress posts on your site
define('WP_USE_THEMES', false);
require('./wordpress_folder/wp-load.php');
query_posts('showposts=1');
?>
Note: If you edit your page and test it out on your computer before uploading it to your site, you wont be able to view it locally after you add in the PHP code, unless you setup something like XAMPP.
Note: I wanted 1 post to show, you can change
query_posts('showposts=1');
just change the number 1 to how many posts you want.
4) The next thing to do is decide where you want to insert the actual posts. Once you know you put this code into that place. This will load in the post Title, a small excerpt, and a Read More link that will link to your blog.
<?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; ?>
After you've done this, upload the desired_page.php onto your server,
rename or remove the old desired_page.html and change any links you have
to that page that don't work now that the page is PHP not HTML.
References:
This corvidworks site has the detailed instructions that i followed,
and explains more of what goes on behind.
Recent Comments