开发者

wordpress loop with jquery .load()

I have a tabbed sidebar widget for showing my "popular articles , recent articles" with 2 separate loops.

I wanted to implement some Ajax on it so I created a new file called recent-articles.php and pasted the recent articles loop

<?php $recent = new WP_Query("cat=23,4&showposts=8"); while($recent->have_posts()) : $recent->the_post();?>
<a href="<?php the_permalink(); ?>">
<h2><?php the_title(); ?></h2></a>
<h3> <?php the_category(); ?> </h3>
<?php endwhile; ?>

and in my header.php file I wrote

<script type="text/JavaScript">
  $(document).ready(function(){
    $("#latestArticles").click(function(){
      $("#tab2").load("<?php bloginfo('template_directory'); ?>/recent-articles.php");
    });
  });
  </script>

"latestArticles" is the ID of tab button

"tab2" is the ID of div container to show m开发者_C百科y loop

whenever I try that , this error appears

Fatal error: Class 'WP_Query' not found in C:\AppServ\www\wordpress\wp-content\themes\mytheme\recent-articles.php on line 1

can any one help ??


You're loading the recent-articles.php file, but when it executes, it doesn't have any way of knowing what a WP_Query class is. For your code to work, you would need to include the file that defines WP_Query in your recent-articles.php file.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜