I have a working AJAX function within WordPress, There I'm looping through HTML to get my posts which then are accessible in my AJAX Success CB where they are appended to their div.
My question:
How would I format my PHP query func values (a while loop, an array and several separate pagination values) for proper use within JavaScript?
Here's what my function looks like as is;
<?php
function _custom_paginate(){
$paged = $_POST['count'];
$args = array(
'posts_per_page' => 12,
'category' => 3,
'paged' => $paged,
'post_status' => 'publish'
);
$query = new WP_Query($args);
if ( $query->have_posts() ) :
while ($query->have_posts()) : $query->the_post(); ?>
<div class="large-3 three columns box">
<div class="thumb">
<?php the_content();?>
<div class="thumb-foot">
<div class="thumbinfo">
<p>Posted on <?php the_time('m.d.Y') ?></p>
</div>
<div class="thumb-social">
<div class="thumb-twitter"></div>
<div class="thumb-facebook"></div>
</div>
</div>
</div>
</div>
<?php
endwhile;
endif;
//Several pagination values
$total_pages = $query->max_num_pages;
if ($total_pages > 1){
$current_page = max(1, get_query_var('paged'));
?>
<div class="pagi-contain">
<div id="pagi" class="large-12">
<!-- Append pagination here #pagi-->
<ul class="pagi">
<li id="ajaxprev" style="float:left;">prev</li>
<li id="pagenum"><?php echo $current_page; echo ' ... '.$total_pages; ?></li>
<li id="total_pages"></li>
<li id="ajaxnext" style="float:right;">next</li>
</ul>
</div>
</div>
<?php
}
exit;
}
You don't have to rewrite this but a lesson in formatting each value into an accessible array(?) for JS to work with each value separately. I found this person seems to have done what I am trying but the subject here is not PHP side...
Here is an example that is hopefully more clear on what I'm attempting to make work. http://jsfiddle.net/BenRacicot/LRmc3/