I want to show a popup in which content comes from the other file.
Right now i am using this code to show a popup when the content for the popup is present on the same page.
jQuery(".item").click(function(e) {
var currentID = jQuery(this).attr("id");
jQuery.ajax({
method: "POST",
url: "some.php",
data: {
name: "John",
location: "Boston"
}
})
.done(function(msg) {
jQuery(".popup-overlay").html(msg);
jQuery("." + currentID).fadeIn(300, function() {
jQuery(this).focus();
});
jQuery(".popup-overlay").show();
});
});
Can i some how put the content to be shown in popup in other file and then pass the path of the file some how in above code
this will the code in ajax.php
<?php include("wp-load.php"); ?>
<div class="popup-overlay">
<?php
$args = array(
'post_type' => 'portfolio',
);
$loop=new WP_Query;
$count=1;
if($loop->have_posts()):whiile(have_posts()) :the_post();
?>
<div class="popup-box <?php echo $count; ?> ">
<div class="inner-box">
</div>
</div>
<?php
$count;
endwhile;
endif;
?>
</div>
Right Now it is getting all the divs in ajax.php.
Rather it should just display the div which has the class=”currentID”
This is a basic example of how to use AJAX in WordPress. It shows how to take a variable from javascript, pass it to a PHP function (altering it slightly), and then pass it back to the javascript.
This assumes you already know how to enqueue javascript, etc.
Javascript Piece (which you can add in header.php or footer.php or in template file in which it is needed.)
PHP Piece (have to include in functions.php)
you can add ajax request like that.
you ajax.php should b like that check it and update me..