Load page content with AJAX using Fancybox?

Here it is. Google use no JS and there is no fancy. Also links can be used with no get, just simple url: page.com/post-name/

On single page:

<?php
$apost = $_GET["type"];
preg_replace('/_/', 'html', preg_replace('/%/', 'html', htmlentities(mysql_real_escape_string($apost))));
?>
<?php if($apost == 'iframe') { ?>
<?php get_header('single'); ?>
<?php if (have_posts()) : while (have_posts()) : the_post();?>
<div class="popup people">
    staff of popup
</div>
<?php endwhile; endif; ?>
</body>
</html> 
<?php } else { ?>

<?php get_header(); ?>
<div class="single">
    <?php if (have_posts()) : while (have_posts()) : the_post();?>
    staff of content
    <?php endwhile; endif; ?>
</div>

<?php get_footer(); ?>

<?php } ?>

On html button or link, etc:

<a href="<?php the_permalink();?>#<?php the_ID(); ?>" data-fancybox-type="iframe" class="various" id="<?php the_ID(); ?>" data-class="<?php echo get_post_type( get_the_ID() ); ?>">View item</a>

In javascript:

$(".results .results_item a").each(function(){
        var hrefParts = $(this).attr('href').split('#');
        $(this).attr('href', hrefParts[0] + '?type=iframe#' + hrefParts[1]);
        });

$("a").fancybox({
    maxWidth    : 615,
    maxHeight   : 2000,
    fitToView   : true,
    width       : '100%',
    height      : '100%',
    autoSize    : false,
    closeClick  : false,
    openEffect  : 'none',
    closeEffect : 'none',
    wrapCSS : 'people' // add a class selector to the fancybox wrap
});

$("a").click(function(event) {
        window.location.hash = this.hash;
    });

    if(window.location.hash) {
      var hash = window.location.hash.substring(1); //Puts hash in variable, and removes the # character
      var new_class_name = $("#" + hash).data("class");
      $("#" + hash).fancybox({
        maxWidth    : 615,
        maxHeight   : 2000,
        fitToView   : true,
        width       : '100%',
        height      : '100%',
        autoSize    : false,
        closeClick  : false,
        openEffect  : 'none',
        closeEffect : 'none',
        wrapCSS : new_class_name // add a class selector to the fancybox wrap
    }).trigger('click');
      // hash found
      } else {
          // No hash found
      }

Leave a Comment