【问题标题】:wordpress loop with jquery .load()带有 jquery .load() 的 wordpress 循环
【发布时间】: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

谁能帮忙??

【问题讨论】:

    标签: jquery load wordpress


    【解决方案1】:

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

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2023-04-10
    • 1970-01-01
    • 1970-01-01
    • 2013-10-22
    • 1970-01-01
    • 1970-01-01
    • 2016-09-04
    • 1970-01-01
    相关资源
    最近更新 更多