【发布时间】:2011-09-13 13:02:35
【问题描述】:
我想写一个自定义的 next/prev 函数来动态地在fancybox弹出窗口中显示帖子信息。因此,我需要使用 PHP 根据当前显示的任何 Post 获取下一个和上一个 Post ID。我知道当前的帖子 ID 是什么,我可以将其发送给函数,但我不知道如何使用该 ID 来获取相邻的 ID。
编辑:这是我目前的代码(不起作用)
<?php
require_once("../../../wp-blog-header.php");
if (isset($_POST['data'])){
$post_id = $_POST['data'];
}else{
$post_id = "";
}
$wp_query->is_single = true;
$this_post = get_post($post_id);
$in_same_cat = false;
$excluded_categories = '';
$previous = false;
$next_post = get_adjacent_post($in_same_cat,$excluded_categories,$previous);
$post_id = $next_post->id;
$title = $next_post->post_title;
$dataset = array ( "postid"=>$post_id, "posttitle"=>$title );
//Because we want to use json, we have to place things in an array and encode it for json.
//This will give us a nice javascript object on the front side.
echo json_encode($dataset);
?>
【问题讨论】:
标签: php jquery ajax wordpress fancybox