您好,欢迎访问一九零五行业门户网

PHP实现内容页面的上一篇下一篇的功能

在内容站或者产品站中,为了更好的用户体验,一般在内容页面中会给出上一篇,下一篇的链接
php实现内容页面的上一篇下一篇的功能的代码
$previous 为上一篇的id
$next_item 为下一篇的id
$id_array = array();//获取该分类按指定排序得到的内容id数组//获取上一篇,下一篇的idif (is_array($id_array)) { reset ($id_array); $counter = 0; foreach ($id_array as $key => $value) { if ($value == (int)$_get['products_id']) { $position = $counter; if ($key == 0) { $previous = -1; // it was the first to be found } else { $previous = $id_array[$key - 1]; } if (isset($id_array[$key + 1]) && $id_array[$key + 1]) { $next_item = $id_array[$key + 1]; } else { $next_item = $id_array[0]; } } $last = $value; $counter++; } if ($previous == -1) $previous = $last;}
其它类似信息

推荐信息