Posted By

mr_wza on 07/16/13


Tagged

ajax wordpress


Versions (?)

Who likes this?

2 people have marked this snippet as a favorite

gregdbarnes
RamDeveloper


WordPress AJAX loop template


 / Published in: PHP
 

  1. <?php
  2. // Our include
  3. define('WP_USE_THEMES', false);
  4. require_once('../../../wp-load.php');
  5.  
  6. // Our variables
  7. $numPosts = (isset($_GET['numPosts'])) ? $_GET['numPosts'] : 0;
  8. $page = (isset($_GET['pageNumber'])) ? $_GET['pageNumber'] : 0;
  9. $catSlug = (isset($_GET['catSlug'])) ? $_GET['catSlug'] : 0;
  10.  
  11. $count = 0;
  12.  
  13. global $query_string;
  14. $args = wp_parse_args($query_string);
  15.  
  16. if($catSlug=='all'){
  17. $args = array(
  18. 'post_type' => 'post',
  19. 'paged' => $page,
  20. 'posts_per_page' => $numPosts,
  21. 'post_status' => 'publish',
  22. );
  23. }else{
  24. $args = array(
  25. 'category_name' => $catSlug,
  26. 'post_type' => 'post',
  27. 'paged' => $page,
  28. 'posts_per_page' => $numPosts,
  29. 'post_status' => 'publish',
  30. );
  31. }
  32. ?>
  33.  
  34. <?php $wp_query = new WP_Query( $args ); ?>
  35.  
  36. <?php
  37. $totalposts = $wp_query->post_count;
  38. while ($wp_query->have_posts()) : $wp_query->the_post();
  39. $count++;
  40. ?>
  41.  
  42. <article id="post-<?php the_ID(); ?>" <?php post_class('clearfix'); ?> role="article" itemscope itemtype="http://schema.org/BlogPosting">
  43.  
  44. <header class="article-header">
  45.  
  46. <div class="date"><?php print get_the_time('j-m-Y'); ?></div>
  47.  
  48. <h1 class="news-title"><?php the_title(); ?></h1>
  49.  
  50. <?php
  51. $postid = get_the_ID();
  52. ?>
  53.  
  54. <p class="byline vcard">
  55. Posted in <?php echo get_cats($postid); ?> by <?php echo get_the_author(); ?>
  56. </p>
  57.  
  58. </header> <!-- end article header -->
  59.  
  60. <section class="entry-content clearfix" itemprop="articleBody">
  61. <?php the_content(); ?>
  62. </section> <!-- end article section -->
  63.  
  64. </article> <!-- end article -->
  65.  
  66. <?php
  67. endwhile;
  68. wp_reset_query();
  69. ?>

Report this snippet  

You need to login to post a comment.