PHP – WordPress – Load Pages by jQuery

The given PHP example load the wordpress pages with jQuery.

Code Example:
<script>
// jQuery Code
$('a').click(function(){
	$('section#page-container').html('<div id="loading"><p>Loading ...</p></div>');
	var $link = this;
	$.ajax({
		url: $link.attr('href'),
		type: 'POST', 
		data: 'ajax=true', 
		success: function(data) {
			$('section#page-container').html(data);
		}
	});
	return false
});
</script>
<?php
// functions.php
function is_ajax_request() {
	if ((isset($_SERVER['HTTP_X_REQUESTED_WITH']) && ($_SERVER['HTTP_X_REQUESTED_WITH'] == 'XMLHttpRequest')) || isset($_GET['ajax']) || isset($_POST['ajax'])) {
		return true;
	}
	else{
		return false;
	}
}

// ------------------------------------------------
if( ! is_ajax_request() ) get_header();

// Page content here

if( ! is_ajax_request() ) get_footer();
// ------------------------------------------------
?>

Post to Twitter Post to Digg Post to Facebook Post to Google Buzz Send Gmail

Leave a Comment

Your email address will not be published. Required fields are marked *