【发布时间】:2012-08-06 22:26:24
【问题描述】:
首先,我认为这是一个远景,但希望有人可以提供帮助。
为了解释当前的情况,目前我有一个自定义插件,它可以获取有关用户及其 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 个帖子并显示它们。
如果有人可以提供帮助,我将不胜感激。
更新
好的,
到目前为止,我已经在我的 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 和这篇文章来拉取正确的帖子:scribu.net/wordpress/wp-pagenavi/…
-
当您说页面无法加载时,您是什么意思?它是否显示一些错误消息?
-
@VladimirKadalashvili - 是的,分页符,虽然没有显示错误消息,但这可能是因为我没有打开错误报告。
-
@Jeremy 谢谢,我会试试看会发生什么!