首先,我认为这是一个很长的过程,但希望有人可以帮助。WordPress的 - 我怎样才能通过AJAX获取更多的职位?
为了解释目前的情况,目前我有一个自定义插件,可以获取有关用户及其最近4篇帖子的各种信息。
我也是用的WPBook插件(所以这是在Facebook和仅仅只是一个典型的WordPress站点)
好了,这里是我的代码是抓住了4所最近发表的文章的用户:
// The Query
query_posts('posts_per_page=4&author='.$blogger_id);
// set $more to 0 in order to only get the first part of the post
global $more;
$more = 0;
// the Loop
while (have_posts()) : the_post();
?>
<div class="oe-grid-box">
<a href="<?php the_permalink() ?>" <?php the_title()?></a>
<div class="oe-grid-box-content">
<?php echo the_content('...'); ?>
</div>
<div class="oe-grid-pic">
<a href="<?php the_permalink() ?>">
<span class="<?php echo strtolower($category); ?>"></span>
</a>
<?php echo $image; ?>
</div>
</div>
<?php
endwhile;
// Reset Query
wp_reset_query();
?>
<div id="load-more">Load More</div>
我尝试下面这个教程,但不是一个单独的插件,配股代码在我现有的插件,但现在我的网页无法加载:
http://www.problogdesign.com/wordpress/load-next-wordpress-posts-with-ajax/
理想情况下,我希望当单击加载更多按钮时,获取4个更多帖子并显示它们。
如果有人可以帮助,我会很感激。
UPDATE
好吧,
到目前为止,我在的jQuery已经添加到调用PHP文件,该文件应该有希望恢复职位,但它不工作。
我在想这是因为它不知道WordPress的功能是什么?
如果我在我的加载脚本中加入了一个简单的echo
,那么jQuery成功函数会显示一个警告,说明它的工作原理,但是如果我开始做WordPress的东西,我会得到一个内部服务器错误, more.php文件:
// load wordpress into template
$path = $_SERVER['DOCUMENT_ROOT'];
define('WP_USE_THEMES', false);
require($path .'/wp-load.php');
$blogger_id = $_GET['id'];
$firstname = $_GET['firstname'];
$surname = $_GET['surname'];
$posts = $_GET['posts'] + 4;
$category = $_GET['category'];
$image = $_GET['image'];
// The Query
query_posts('paged='.get_query_var('paged').'&posts_per_page=' . $posts . '&author='.$blogger_id);
// set $more to 0 in order to only get the first part of the post
global $more;
$more = 0;
// then the same loop as in my page that is making the ajax call.
嗯,我会用jQuery和这篇文章来拉正确的帖子:http://scribu.net/wordpress/wp-pagenavi/right-way-to-use-query_posts.html – Jeremy 2012-08-09 16:46:40
当你说临时页不会加载,你是什么意思?它是否显示一些错误消息? – 2012-08-09 16:49:19
@VladimirKadalashvili - 是的,分页符,没有显示错误消息,但可能是因为我没有打开错误报告。 – martincarlin87 2012-08-10 08:08:10