我想在一个单独的php文件上运行wp_query进行ajax调用 [英] I want to run wp_query on a separate php file for an ajax call
本文介绍了我想在一个单独的php文件上运行wp_query进行ajax调用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
例如:
<?php $numposts = $_POST['showposts']; ?>
<?php $home_query_bottom = new WP_Query("cat=&showposts=$num_posts&offset=5"); $b = 0; ?>
<ul class="thumbs">
<?php while ($home_query_bottom->have_posts()) : $home_query_bottom->the_post();
$do_not_duplicate = $post->ID; $b++; ?>
<li class="post-<?php the_ID(); ?> thumb"><?php get_the_image( array( 'custom_key' => array( 'thumbnail' ), 'default_size' => 'thumbnail', 'width' => '160', 'height' => '160' ) ); ?></li>
<?php endwhile; wp_reset_query(); $b = 0; ?>
</ul>
上面的代码位于其自己的php文件中,可以由主wordpress页面调用,但是我收到一条错误消息,指出未找到wp_query类.我假设这是因为我没有使用header.html,它可能包含很多包含.该页面需要什么才能利用wp_query类?
The code above is on its own php file ready to be called by the main wordpress page, however I get an error saying wp_query class not found. I'm assuming it's because I am not using the header.html which probably has a bunch of includes. What do I need for that page to utilize the wp_query class?
推荐答案
您必须使ajax称为模板页面的页面. 在您的博客中创建一个新页面并分配模板. 没有标题,没有头文件.
You have to make the page that ajax calls a template page. Make a new page in your blog and assign the template. no headers no includes.
这篇关于我想在一个单独的php文件上运行wp_query进行ajax调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文