Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <div id="single-post-container"></div>
- <?php if (have_posts()) : while (have_posts()) : the_post(); ?>
- <a class="post-link" rel="<?php the_ID(); ?>" href="<?php the_permalink(); ?>">
- <?php the_title(); ?>
- </a>
- <?php endwhile; endif; ?>
- <?php
- $post = get_post($_POST['id']);
- ?>
- <div id="single-post post-<?php the_ID(); ?>">
- <?php while (have_posts()) : the_post(); ?>
- <?php the_title();?>
- <?php the_content();?>
- <?php endwhile;?>
- </div>
- $(document).ready(function(){
- $.ajaxSetup({cache:false});
- $(".post-link").click(function(){
- var post_link = $(this).attr("href");
- $("#single-post-container").html("content loading");
- $("#single-post-container").load(post_link);
- return false;
- });
- });
- <div id="project-container"></div>
- <?php if (have_posts()) : while (have_posts()) : the_post(); ?>
- <a class="post-link" rel="<?php the_ID(); ?>" href="<?php the_permalink(); ?>">
- <?php the_title(); ?>
- </a>
- <?php endwhile; endif; ?>
- <div id="single-post post-<?php the_ID(); ?>">
- <?php while (have_posts()) : the_post(); ?>
- <?php the_title();?>
- <?php the_content();?>
- <?php endwhile;?>
- </div>
- /**
- * Enqueue scripts and styles.
- */
- function starter_scripts() {
- wp_deregister_script( 'jquery' );
- wp_register_script( 'jquery', includes_url( '/js/jquery/jquery.js' ), false, NULL, true );
- wp_enqueue_script( 'jquery' );
- wp_enqueue_style( 'starter-style', get_stylesheet_uri() );
- wp_enqueue_script( 'includes', get_template_directory_uri() . '/js/min/includes.min.js', array('jquery'), '', true );
- wp_enqueue_script( 'gray', get_template_directory_uri() . '/js/min/jquery.gray.min.js', array('jquery'), '', true );
- wp_localize_script( 'includes', 'site', array(
- 'theme_path' => get_template_directory_uri(),
- 'ajaxurl' => admin_url('admin-ajax.php')
- )
- );
- }
- add_action( 'wp_enqueue_scripts', 'starter_scripts' );
- /**
- * AJAX nopriv
- */
- add_action('wp_ajax_load-single-post', 'prefix_ajax_single_post');
- add_action('wp_ajax_nopriv_load-single-post', 'prefix_ajax_single_post');
- function prefix_ajax_single_post() {
- $pid = (int) filter_input(INPUT_GET, 'pID', FILTER_SANITIZE_NUMBER_INT);
- if ($pid > 0) {
- global $post;
- $post = get_post($pid);
- setup_postdata($post);
- printf('<div id="single-post post-%d">', $pid);
- the_title();
- the_content();
- echo '</div>';
- }
- exit();
- }
- // Load posts via AJAX
- (function($, D){
- $.ajaxSetup({cache:false});
- $(".post-link").click(function(){
- var postID = $(this).attr('rel');
- var $container = $("#project-container");
- $container.html("content loading");
- $.get(D.ajaxurl, {action: 'load-single-post', pID: postID}, function(content) {
- $container.html(content);
- });
- });
- })(jQuery, site);
- $post = get_post($_POST['id']);
- function is_ajax() {
- return isset($_SERVER['HTTP_X_REQUESTED_WITH'])
- && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest';
- }
- if (is_ajax()) {
- // open here <html>, <head> and <body> tags
- }
- // page content here
- if (is_ajax()) {
- // close here <html>, <head> and <body> tags
- }
- add_action('wp_enqueue_scripts', function() {
- // $script_url is the full url to your js file
- wp_enqueue_script('myjs', $script_url, array('jquery'), true, null, true);
- wp_localize_script('myjs', 'myData', array('ajaxurl' => admin_url('admin-ajax.php));
- });
- add_action('wp_ajax_load-single-post', 'prefix_ajax_single_post');
- add_action('wp_ajax_nopriv_load-single-post', 'prefix_ajax_single_post');
- function prefix_ajax_single_post() {
- $pid = (int) filter_input(INPUT_GET, 'pID', FILTSER_SANITIZE_NUMBER_INT);
- if ($pid > 0) {
- global $post;
- $post = get_post($pid);
- setup_postdata($post);
- printf('<div id="single-post post-%d">', $pid);
- the_title();
- the_content();
- echo '</div>';
- }
- exit();
- }
- (function($, D){
- $.ajaxSetup({cache:false});
- $(".post-link").click(function(){
- var postID = $(this).attr('rel');
- var $container = $("#single-post-container");
- $container.html("content loading");
- $.get(D.ajaxurl, {action: 'load-single-post', pID: postID}, function(content) {
- $container.html(content);
- });
- });
- })(jQuery, myData);
Add Comment
Please, Sign In to add comment