WordPress获取第一个和最后一个帖子ID [英] WordPress get the first and the last post ID

查看:115
本文介绍了WordPress获取第一个和最后一个帖子ID的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

显示单个帖子时,我具有上一个/下一个链接.这是可行的,但是我希望在显示最后一个帖子时,下一个"链接指向第一个帖子,而在显示第一个帖子时,上一个"链接指向最新的帖子.根据文档,get_boundary_post()应该能够获取第一条或最后一条帖子.这是我的single.php中的内容:

 <?php 
 $ prev_post  = get_adjacent_post(true,' ',true);
 $ next_post  = get_adjacent_post(true,' ',false);
if($ next_post == ' ')
{
 $ next_post  = get_boundary_post();
}
if($ prev_post == ' ')
{
 $ prev_post  = get_boundary_post(); //  ??? 
}
 $ prev_post_id  = $ prev_post-> ID;
 $ next_post_id  = $ next_post-> ID;

<   a     ="  <?php echo get_permalink($ prev_post);?> " <  > 
<   a     ="  <?php echo get_permalink($ next_post);?> " <  > 

?> 



获取最后一个帖子的第一个帖子链接有效,但是获取第一个帖子的最新帖子链接则无效.我不确定如何调用get_boundary_post()来获取最新帖子,我尝试将其"start"参数设置为false(默认为true),但链接仍指向第一篇帖子. div class ="h2_lin">解决方案

prev_post = get_adjacent_post(true,' ',是);


next_post = get_adjacent_post(true,' ',false); if(


next_post == ' ') {


When displaying a single post I have previous / next links. This works but I would like the ''next'' link to point to the first post when the last post is displayed and the ''previous'' link to point to the latest post when the first post is displayed. According to the documentation get_boundary_post() should be able to get the first or the last post. Here is what is in my single.php:

<?php
	$prev_post = get_adjacent_post( true, '', true );
	$next_post = get_adjacent_post( true, '', false );
	if($next_post == '')
	{
		$next_post = get_boundary_post();
	}
	if($prev_post == '')
	{
		$prev_post = get_boundary_post(); //???
	}
	$prev_post_id = $prev_post->ID;
	$next_post_id = $next_post->ID;   

<a href="<?php echo get_permalink($prev_post); ?>">previous</a>
<a href="<?php echo get_permalink($next_post); ?>">next</a>

?>



Getting the first post link for the last post works, but getting the latest post link for the first post doesn''t. I''m not sure how to call get_boundary_post() to get the latest post, I''ve tried to set its ''start'' parameter to false (default is true) but the link still points to the first post.

解决方案

prev_post = get_adjacent_post( true, '', true );


next_post = get_adjacent_post( true, '', false ); if(


next_post == '') {


这篇关于WordPress获取第一个和最后一个帖子ID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆