带有jquery .load()的wordpress循环 [英] wordpress loop with jquery .load()

查看:79
本文介绍了带有jquery .load()的wordpress循环的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带标签的侧边栏小部件,用于显示我的热门文章,最近的文章" 有2个独立的循环.

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

我想在其上实现一些Ajax,因此我创建了一个名为last-articles.php的新文件,并粘贴了最新文章循环

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; ?>

在我写的header.php文件中

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"是选项卡按钮的ID

"latestArticles" is the ID of tab button

"tab2"是显示我的循环的div容器的ID

"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 ??

推荐答案

您正在加载central-articles.php文件,但是在执行该文件时,它无法知道WP_Query类是什么.为了使代码正常工作,您需要在最近的articles.php文件中包含定义WP_Query的文件.

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.

这篇关于带有jquery .load()的wordpress循环的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆