0

I'm trying to create a lightbox effect for a self-made WordPress Theme. But I'm trying to include a WordPress page in the body through jQuery.

For example, in my js file.

    $('.button').Click(function(){

    $(body).append('`<div><?php get_template_part('content','thing'); ?></div>`');

});

I've tryed that and then my php file doesn't reproduce the php bit.

Thanks.

2
  • 2
    PHP won't be parsed in *.js files by default. Either rename your JavaScript file to end in .php or edit your .htaccess, Clicky. Commented Oct 5, 2015 at 19:04
  • this article on how to use ajax in wordpress may help you. and these are other resources on the subject Commented Oct 5, 2015 at 19:51

2 Answers 2

1

try

  $('.button').Click(function(){

    $(body).append("<div><?php get_template_part('content','thing'); ?></div>");

});

Remember to use this jquery in a php file not in JS file.


it might help you

Sign up to request clarification or add additional context in comments.

Comments

1

You can call a ajax functions that returns your php result.

Like (Seems you're using jQuery):

$.get("templatepart.php", function(data) {
  $(body).append("<div>"+ data +"</div>");
})

And in your php file ("templatepart.php"):

<?php
  // after includes/requires/etc functions
  get_template_part('content','thing');
?>

1 Comment

this wouldn't work because wordpress is not loaded in templatepart.php, so get_template_part is not defined

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.