$res = M('img')->where('type=2')->field('id,title')->select();
$k = array_search($id, array_column($res, 'id'));
$last = $res[$k - 1];
$next = $res[$k + 1];
array_column 把二维数组的 id 拿出来 为 一维数组
array_search 通过 $id 搜索 得到 该id的位置 return $k 键名(下标)
<span class="node-g g-a cr-6">上一篇:</span>
{if condition="$last.id eq NULL"}
<span class="status" style="color: rgb(88, 87, 86);">{$last.id}没有了...</span>
{else/}
<span class="node-g g-b cr-m1"
data-url="{:U('understandus/us_shipingDetails',array('id'=>$last['id']))}">{$last.title}</span>
{/if}