crazyyy
4/28/2014 - 11:40 AM

WordPress: load post with AJAX

WordPress: load post with AJAX

***************  HEADER
<script>
	$(document).ready(function(){  
	  
	    $.ajaxSetup({cache:false});  
	    $(".trick").click(function(){  
	        var post_id = $(this).attr("rel");  
	        $("#single-home-container").html("loading...");  
	        $("#single-home-container").load("http://<?php echo $_SERVER[HTTP_HOST]; ?>/single-home/",{id:post_id});  
	    return false;  
	    });  
	  
	});  
	</script>
    
***************** INDEX IN POST

<a class="trick" rel="<?php the_ID(); ?>" href="<?php the_permalink();?>"><?php the_ID(); ?> <?php the_title(); ?></a>


*************** INDEX {LACE TO LOAD 

<div id="single-home-container"></div>  

******************* SINGL HOME TEMPLATE 
<?php  
  
    /* 
    Template Name: single-home 
    */  
  
?>      
<?php  
      $post = get_post($_POST['id']);  

?>  
  <?php the_ID(); ?>
    <!--single-home-->  
    <div id="single-home post-<?php the_ID(); ?>">  
        <!--sh-post-->  
        <div class="sh-post">  
            <!--sh-content-->  
            <div class="sh-content">  
				<?php 

					echo '<h1>'.$post->post_title.'</h1>'; // Выводим заголовок записи;
					echo '<p>'.$post->post_content.'</p>'; // Выводим контент записи;
				?>
            </div>  
            <!--sh-content-->  
    </div>  
    <!--sh-post-->          
    <div class="clearfix"></div>      
    </div>  
    <!--single-home-->  



http://wp-kama.ru/function/get_post
http://school-wp.net/spravochnik/posts-pages/get_post/
not working http://stanislav.it/load-wordpress-post-content-with-ajax-and-jquery/