I want to AJAX post content into a pop-up div when I click on the post / page link. I have come up with the following code:
Relevant HTML / PHP:
<ul class="links">
<?php if (have_posts()) : ?>
<?php while (have_posts()) : the_post(); ?>
<li><a href="<?php the_permalink() ?>"><?php the_title();?></a></li>
<?php endwhile; endif; ?>
</ul>
<div id="hover-box"></div>
jQuery:
$('#hover-box').hide();
$('.links a').click(function( ) {
var url=$(this).attr('href');
$('#hover-box').fadeIn();
$('#hover-box').load(url + ' article');
return false;
});
This works fine, but I'm wondering if anyone could point out the drawbacks to this approach. Other solutions I've found (e.g. https://wordpress.stackexchange.com/a/41062/18329) seem much more complicated. Should I be using additional PHP? Other solutions also make use of admin-ajax.php (e.g. http://deadlyhifi.com/2011/12/loading-frontend-ajax-content-in-wordpress/).
Any help / advice greatly appreciated!