带有jquery .load()的wordpress循环

| 我有一个带标签的侧边栏小部件,用于显示我的“热门文章,最近的文章” 有2个独立的循环。 我想在其上实现一些Ajax,因此我创建了一个名为last-articles.php的新文件,并粘贴了最新文章循环
<?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; ?>
在我的header.php文件中
<script type=\"text/JavaScript\">
  $(document).ready(function(){
    $(\"#latestArticles\").click(function(){
      $(\"#tab2\").load(\"<?php bloginfo(\'template_directory\'); ?>/recent-articles.php\");
    });
  });
  </script>
\“ latestArticles \”是选项卡按钮的ID \“ tab2 \”是显示我的循环的div容器的ID 每当我尝试时,都会出现此错误
Fatal error: Class \'WP_Query\' not found in C:\\AppServ\\www\\wordpress\\wp-content\\themes\\mytheme\\recent-articles.php on line 1
谁能帮忙??     
已邀请:
您正在加载Latest-articles.php文件,但是在执行该文件时,它没有任何方法可以知道WP_Query类是什么。为了使您的代码正常工作,您需要在最近的articles.php文件中包含定义WP_Query的文件。     

要回复问题请先登录注册