我想在单击帖子/页面链接时将内容AJAX发布到弹出式div中。我想出了以下代码:
相关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;
});
这很好,但我想知道是否有人可以指出这种方法的缺点。我找到的其他解决方案(例如。https://wordpress.stackexchange.com/a/41062/18329) 看起来要复杂得多。我应该使用其他PHP吗?其他解决方案也使用管理ajax。php(例如。http://deadlyhifi.com/2011/12/loading-frontend-ajax-content-in-wordpress/).非常感谢您的帮助/建议!