I have a static HTML website. It contains a wordpress blog. I’m trying to have snippets of my last three blog post appear on my homepage. It should contain the title to the blog post, which is clickable to the post as well as a “click here” link to the post after about a 20 word snippet. How do you do this?
The site is located at http://www.capitalsolutionsonline.net
I have the seo for wordpress plugin installed in case that plays into it.
I have searched high and low for a solution that works with no luck
Any ideas?
Thanks in advance!
With a static HTML page it won’t be possible to show the last 3 blog posts, if it was a static PHP page however it will work. The most simple way to change the page to be PHP is simply by changing .html to .php.
To get the blog posts however read through the following Wordpress codex article and let me know if it makes sense and try to attempt building your own code otherwise let me know if your stuck and i can help you.
http://codex.wordpress.org/Template_Tags/get_posts
Yes, I’m stuck. I just have a basic understanding of html and css (enough to build the site). I really need help with this.
By the way, keep SEO (and my current rankings) in mind is of upmost importance.
Hey bud, sorry for the long delay. I have been working on a freelance job and got side tracked with threads i posted in. Until Tuesday when this freelance job is done i don’t have time to help you build the script you will need but i can say if anything your SEO will improve with the recent blog posts as Google will have more information to chew on. The only thing that will bring down SEO from a semantic point will be incorrect SEO markup which i understand a little more with each day that goes by.
Contact me when you have time. I appreciate your help.
Sorry for the long delay bug, to be honest i forgot that i was helping you with this so i will basically outline what needs to be done. To start off with we need to include a key file in your WordPress directory called wp-blog-header.php, this file loads all the key functionality we need including posts and pages.
So basically the below is what we need to start off with…
<?php
// Request the required WordPress files needed to query the last
// three blog posts
define('WP_USE_THEMES', false);
require('./path-to-wordpress/wp-blog-header.php');
?>
So with the above code rather then allowing WordPress to load the default theme we can turn this feature off which i have done by setting WP_USE_THEMES to false, the next thing you will notice is the key words “path-to-wordpress” which is the relative path to your WordPress installation. The next thing we need to do is create a new WP_Query which is a built in function that allows for custom database queries using simple array property values.
<?php
// Request the required WordPress files needed to query the last
// three blog posts
define('WP_USE_THEMES', false);
require('./path-to-wordpress/wp-blog-header.php');
// Query the last three blog posts
query_posts('showposts=3');
?>
Now that we have that we can finally and most importantly move onto the famous WordPress loop called The Loop, basically this allows us to manipulate the way we run through the while loop which allows for a much easier and faster loop to work with. See the below for the complete code with The Loop.
<?php
// Request the required WordPress files needed to query the last
// three blog posts
define('WP_USE_THEMES', false);
require('./path-to-wordpress/wp-blog-header.php');
// Query the last three blog posts
query_posts('showposts=3');
// Lets run "The Loop"
if (have_posts()) {
while (have_posts()) {
the_post();
echo '<div id="post-' . the_ID() . '" ' . post_class() . '>';
echo ' <h3><a href="' . the_permalink() . '">' . the_title() . '</a></h3>';
echo ' <p>' . the_content() . '</p>';
echo '</div>';
}
} else {
echo '<p>No posts exist in the blog!</p>';
}
?>
The above is the most basic form of the WordPress loop in action but you can customize it to output and work however you need given its within the abilities that WordPress can handle. I hope there are no hard feelings for the delay and that this helps you get a start on integrating your blog into your static landing page.
No worries on the delay. Your helping me and I really appreciate it.
To clarify my site is a HTML site with a wordpress blog attached to it. It’s located at Commercial Truck Financing - Bad Credit - Capital Solutions. with the blog being /truckers-blog (I hope I can post that on here!).
Where do I put the coding?
Again, I really appreciate your help with this!
Basically the first thing you need to do is change the file extension for index.html so it reads index.php instead as typically phtml isn’t generally supported by any web server these days.
Once you have that done find a spot (more then likely in the center of your page content) and add the last snippet of code i posted above, the next thing you need to do is change “path-to-wordpress” so the path reads “./truckers-blog/wp-blog-header.php” instead.
Just so its a little easier see the example below…
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>WordPress blog integration</title>
</head>
<body>
<h1>Main content</h1>
<p>This is some example content that goes before the blog posts</p>
<h2>Blog Posts</h2>
<?php
// Request the required WordPress files needed to query the last
// three blog posts
define('WP_USE_THEMES', false);
require('./path-to-wordpress/wp-blog-header.php');
// Query the last three blog posts
query_posts('showposts=3');
// Lets run "The Loop"
if (have_posts()) {
while (have_posts()) {
the_post();
echo '<div id="post-' . the_ID() . '" ' . post_class() . '>';
echo ' <h3><a href="' . the_permalink() . '">' . the_title() . '</a></h3>';
echo ' <p>' . the_content() . '</p>';
echo '</div>';
}
} else {
echo '<p>No posts exist in the blog!</p>';
}
?>
</body>
</html>
Won’t changing the file from .html to .php hurt my seo, rankings?
No, SEO rankings on Google for example don’t care about the file types you use. Google as the example is more interested in the keywords on the page and that’s about it.
I’m swamped with work over here. I’ll be able to get back to this over the weekend.