PHP & Jquery in WordPress
-
I’m trying to load some php into a div after the first image of a wordpress post. I thought that with Jquery’s selectors it was natural to use Jquery for the job.
Initially I tried:
$j(document).ready(function() {
$j(‘p:first’).append(‘<?php include(‘new-box.php’); ?>’)
});But that didn’t seem to work.
Then, I DID successfully add the div using:
$j(document).ready(function() {
$j(‘p:first’).append(‘<div id=”new-box”>Ooga Booga
</div>’)
});But I could not get anything into the div with .load. I first tried:
$j(document).ready(function() {
$j(‘p:first’).append(.load(“new-box.php”));
});Then I tried putting in the div first then loading the content like so:
var $j = jQuery.noConflict();
$j(document).ready(function() {
$j(‘p:first’).append(‘<div id=”new-box”>hooga
</div>’)
$j(“#new-box”).load(“new-box.php”);
});The file listed is in the theme dir of WP. My thoughts are that WP is making the relative url’s wonky, but I can’t see to get php calls like template_url() working in the .load().
Any suggestions?
Thanks!
- The topic ‘PHP & Jquery in WordPress’ is closed to new replies.