我正在尝试设置一个WordPress主题,用AJAX加载页面(而不是帖子).我正在按照本指南操作,但无法正确加载页面.
这些帖子的链接正在使用post slug生成
http://local.example.com/slug/
Run Code Online (Sandbox Code Playgroud)
所以我调整了
jQuery(document).ready(function($){
$.ajaxSetup({cache:false});
$("a.bar").click(function(e){
$('page-loader').show();
var that = $(this).parent();
$('.column').not($(this).parent()).animate({width: 'toggle',opacity:'0.75'}, 700, function() {
});
var post_id = $(this).attr("href");
$("#page-container").load("http://<?php echo $_SERVER[HTTP_HOST]; ?>" + post_id,{id:post_id});
return false;
});
});
Run Code Online (Sandbox Code Playgroud)
URL是正确的,但它不加载任何东西..
<?php
/*
Template Name: Triqui Ajax Post
*/
?>
<?php
$post = get_post($_POST['id']);
?>
<?php if ($post) : ?>
<?php setup_postdata($post); ?>
<div <?php post_class() ?> id="post-<?php the_ID(); ?>">
<h2><?php the_title(); ?></h2>
<small><?php the_time('F jS, Y') ?> <!-- by <?php the_author() ?> --></small>
<div …Run Code Online (Sandbox Code Playgroud)