Gravatar WordPress Comments

Today I searched gravatar wordpress comments trying to figure how to get the gravatar images next to the comments in a wordpress.org theme. I was surprised to find that wordpress natively supports gravatars in 2.5 and above. To use it you just call get_avatar and pass in the email and an optional size and it spits out the image html. Once I found the loop of comments in the template code, I just added the below code in a div next to the comment text.

I used comment_author_email on the php comment object to get the email address of the person who made the comment. It was pretty painless to do and a great feature to add to my template.

PHP 301 Redirect

Today I searched PHP 301 Redirect and I found that it was very simple. All you need to do is add this code to the header of the the php page.

Then you just change “http://www.new-url.com” to the url you want the page to get redirect to. Once that is done you have successfully redirected a page using a 301 redirect.

Multi Select PHP

Today I searched multi select php to find out how php handled the passing of this input field. I found out that you need add the square brackets to the end of the name value of your select element for PHP to pick up all of the values in an array. Below is an example of the code:

The Multiple Select Box

The HTML


The PHP

	$selectData=$_POST['selectData'];
	if ($selectData){
	    foreach ($selectData as $sd){
               echo 'Selected Value '.$sd;
            }
	}

Make AJAX Call To A Different Domain Using PHP & JQuery

Today I Searched how to make an AJAX call to a URL on a different domain. My first attempt failed with a security error. I dug into the problem a bit and found out that PHP can be used as a proxy to fetch the web content.

AJAX Calls PHP Script On Your Domain -> PHP Script Fetches Content From Remote Domain -> PHP Script Returns The Remote Data Back To The AJAX Call

Below is a sample PHP script that I found and tweaked.

// Set your return content type
header('Content-type: text/html');

// Website url to open
$daurl = 'http://www.otherdomain.com/index.php?sku=' . $_GET["sku"];

// Get that website's content
$handle = fopen($daurl, "r");

// If there is something, read and return
if ($handle) {
    while (!feof($handle)) {
        $buffer = fgets($handle, 4096);
        echo $buffer;
    }
    fclose($handle);
}

Below is the AJAX call to load the content into a div using JQuery

$("#loadremotecontent").load('getprice.php?sku=322000');

The script could be further modified to pass in the entire URL as a parameter so it could be more generic. I would love to hear about other cross domain AJAX options if anyone has any other suggestions.

Go back to top