【发布时间】:2011-09-02 02:07:44
【问题描述】:
我有一个标签式侧边栏小部件,用于显示我的“热门文章、最近文章” 有 2 个独立的循环。
我想在它上面实现一些 Ajax,所以我创建了一个名为 recent-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
谁能帮忙??
【问题讨论】: