Getting WordPress post titles asyncronously using Ajax…

Getting WordPress post titles asyncronously using Ajax…

Ajax logoAssuming you already have a pretty good knowledge of JavaScript, this post should just be recap or simple enough to understand.

I know this method can also be done using the YUI framework with slightly less code but I wanted a relatively simple, raw and quick way to populate a div using Ajax to dynamically update my most recent WordPress blog posts on my homepage. I built my site before WordPress got the in thing, so i just skinned a theme and went from there. I’d previously been using a JavaScript jump list which I’d had to manually update after each post and it was tedious work. I’ll show the YUI example also later. For this simple task though, I chose 5 posts (or my page) as being an ample amount to display (later cutting that to the the most recent post) and as I’ve been dabbling with Ajax recently, I thought I’d use that method and a server side PHP module to interact with the Ajax via a GET request, communicating asyncronously on page load. For testing, I kept all the code in just one page just to make matters simple and debugging easy but naturally as I want to use an unobtrusive method and in order to remove clutter, I later removed the JavaScript into an external file of it’s own. Continue reading