很多搜索和测试都没有成功,我需要一位专家来拯救我。
我需要在worpdress中进行自定义帖子查询,它只返回从特定帖子开始的5篇帖子。换句话说,单曲中有一个div。php,我需要从当前帖子开始的5篇帖子的列表(由single.php返回的帖子)
我希望我说得很清楚,谢谢你的宝贵帮助。
很多搜索和测试都没有成功,我需要一位专家来拯救我。
我需要在worpdress中进行自定义帖子查询,它只返回从特定帖子开始的5篇帖子。换句话说,单曲中有一个div。php,我需要从当前帖子开始的5篇帖子的列表(由single.php返回的帖子)
我希望我说得很清楚,谢谢你的宝贵帮助。
您可以使用get_adjacent_post()
和过滤器get_previous_post_where
或get_next_post_where
. 你会打电话的get_adjacent_post()
正常,但您需要更改LIMIT
至5,使用过滤器。
从这个问题上,我不确定你是否想让现在的职位成为第一位。如果需要,则需要设置LIMIT
到4,然后使用当前postdata生成第一篇文章。
我将创建一个post id数组,然后使用get_post()
当你遍历它们时,我相信get_adjacent_post()
将从数据库返回原始行。
您必须不断重置$post变量,以推进循环post计数器。
使用类似以下内容:
global $post;
get_header(); ?>
<div id="container">
<div id="content" role="main">
<?php
/* Run the loop to output the post.
* If you want to overload this in a child theme then include a file
* called loop-single.php and that will be used instead.
*/
if(have_posts()) while(have_posts()): the_post();
the_title();
for($i = 0;$i < 4;$i++)
{
$post = get_next_post();
setup_postdata($post);
if(!empty($post))
{
echo \'<br/>\';
the_title();
//or whatever code you need to output
}
else
{
//no next post found
}
}
endwhile;
wp_reset_postdata();
?>
</div><!-- #content -->
</div><!-- #container -->
我正在做一个需要使用wp_ajax 行动我跟踪了this guide 设置它与在函数中添加请求对象AJAX文件的区别。php,还添加了if(isset($_REQUEST[\'action\'])) { do_action(\'wp_ajax_\'.$_REQUEST[\'action\']); do_action(\'wp_ajax_nopriv_\'.$_REQUEST[\'action\']); } 让它发挥作用。问题是,显然要将文件放入函数中。ph