wordpress 循环与 jquery .load()
我有一个选项卡式侧边栏小部件,用于显示我的“热门文章、最近文章” 有2个独立的循环。
我想在它上面实现一些 Ajax,所以我创建了一个名为centre-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”是 ID div 容器来显示我的循环,
每当我尝试这样做时,都会出现此错误,
Fatal error: Class 'WP_Query' not found in C:\AppServ\www\wordpress\wp-content\themes\mytheme\recent-articles.php on line 1
有人可以帮忙吗?
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 my 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 ??
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您正在加载recent-articles.php 文件,但是当它执行时,它没有任何方法知道WP_Query 类是什么。为了使您的代码正常工作,您需要将定义 WP_Query 的文件包含在您的centre-articles.php 文件中。
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.