问题描述:

Im having trouble figuring out how to run this PHP inside the following Javascript?

Here is my PHP:

<?php query_posts('post_type=calendar');

if (have_posts()) : while (have_posts()) : the_post(); ?>

{

title: '<?php the_field('program_title'); ?>',

url: '<?php the_field('link'); ?>',

start: '<?php the_field('start_date'); ?>',

end: '<?php the_field('end_date'); ?>'

},

<?php endwhile; endif; ?>

Here is my Javascript:

<script type="text/javascript">

$(document).ready(function() {

$('#calendar').fullCalendar({

header: {

left: 'prev,next today',

center: 'title',

right: 'month,basicWeek,basicDay'

},

editable: false,

eventLimit: true, // allow "more" link when too many events

events: [

PHP GOES HERE

]

});

});

</script>

网友答案:

Since I cannot comment

I am assuming the_field() is returning some sort of value. Does the function output (echo/print/etc) the value? If not, try outputting it

{       
title: '<?php echo the_field('program_title'); ?>',
url: '<?php echo the_field('link'); ?>',
start: '<?php echo the_field('start_date'); ?>',
end: '<?php echo the_field('end_date'); ?>'  
},

Also, you may want to look up php's function json_encode(). That may be of use to you in this scenario.

相关阅读:
Top