I have a big problem and no clue how to solve it 🙂 I want to add a “module” to my homepage (static homepage, not blog posts) that will display the 2 latest blog posts in a very particular way and link back to them. The posts would only display on the homepage and not every other page but the php template used for the page is shared with all the custom pages.
Here is a quick sketch of it
A site that does this beautifully on their homepage is SEOmoz ( but i don’t need that much functionality, only blog post title, thumb, excerpt & link to read more )
Is there a simple way to do this? (plugins, code you can copy/paste from anywhere?) or can I pay someone to write this up for me?
Personally, I like using
get_posts()
(Codex ref) for quick-and-dirty Loops.In your
front-page.php
template file, try the following:Again, you’ll need to modify the HTML markup according to your needs.
An even easier way to do this is to make a page-x.php file in your theme. X is the ID of the page you’re going to use as a homepage. This assumes you have FTP access which you must since you can create files. For instance, the page-2.php would be the template used for the default WordPress sample page. But you can’t just use if (have_posts()) since you’re on a page and that will pull up the pages content that you’re on.
It would be better to use a WP_Query.
Then continue with your loop. Let me know if you need more detail. Where I have
‘news’ should be changed to the SLUG of your category.
Nice handwriting 🙂
This can be simply done by checking whether the current page is home, and by fetching the two latest blog posts.
This will show the blog post titles linked to the blog posts themselves. Insert any other function that will fetch the info you need (eg, the_excerpt() ).
You can add parameters to your query in order to make it more precise, eg, retrieve posts from a specific category only.