Quite often recently when building WordPress themes for smaller sites (ones that have a brochure feel, but have a blog section), the design has included an area on the frontpage, or footer that shows a list of the latest blog posts.

I’ve got a little loop that I use for this area, shown below:

Apart from the cut_str_length function – which I haven’t included – this makes use of WordPress functions and in-built PHP functions to strip the text out of the content so that I have don’t have any images in the way or any formatting, so I can apply my own.

Since the setup_postdata() function seems to have a “special relationship” with $post, we grab a copy before and restore after the function so that you can use it anywhere in the page – inside, or outside the loop – and it shouldn’t affect the rest of your page.

Image Credit: Jasmic