PHP archive

Calling a Wordpress loop from inside a Wordpress loop

Recently I came across a sitution whereby I wanted to call a list of Wordpress posts from inside the body of another post, i.e., not coding it into a template, but embedding into the body of the post itself. Not a big drama, I thought to myself: I already have the exec-php plugin installed to enable the execution of PHP from within Wordpress posts, so all I needed to do was call the Wordpress loop from the point inside the post where I wanted my list of links to appear, e.g.:

<ul>
<php $my_query = new WP_Query('cat=XX');
  while ($my_query->have_posts()) : $my_query->the_post(); ?>
	<li><a href="<php the_permalink(); ?>"><php the_title(); ?></php></a></li>
</php><php endwhile; ?>
</php></ul>

More on Calling a Wordpress loop from inside a Wordpress loop

Fetching posts in Wordpress and ExpressionEngine with jQuery and AJAX

Recently I was asked by a client to do some customisation of a Wordpress site to enable a site visitor to load posts from a certain category into the same part of the page via AJAX. This could have been done in a couple of different ways – using AJAX as requested; or all the posts could’ve been printed to the page, with javascript then used to hide all but one and also used to navigate between them in some sort of hide/show, fading/sliding effect. I’ve done similar things like this before using jQuery, but there were two reasons why I didn’t go that route on this occasion:

  1. With javascript turned off, all the posts from the selected category would’ve been displayed on the page and as the design called for three short columns of text on the page, having one column much, much longer than the other two would really have looked wrong.
  2. The client specifically asked for AJAX to be used.

More on Fetching posts in Wordpress and ExpressionEngine with jQuery and AJAX

Checking backlinks with Yahoo’s Site Explorer Inbound Links API

Recently I wanted to create a page that would list the backlinks to certain sites that I had chosen. Yahoo always seems to have the most comprehensive list of backlinks and luckily they also make available a series of APIs that enables you to access their data. Using the Site Explorer Inbound Links API, and an example of a script towards the bottom of that page, I was able to put together a script that closely mirrors the sort of results you would get if you entered a site’s URL into Yahoo’s Site Explorer.

More on Checking backlinks with Yahoo’s Site Explorer Inbound Links API