🔥码云GVP开源项目 12k star Uniapp+ElementUI 功能强大 支持多语言、二开方便! 广告
# prenext 上一篇下一篇(高级)标签 ## 上下篇(数组)标签 在内容页,根据当前文档调取上一篇、下一篇文档。 ## 示例 获取当前文档上一篇 ``` <pre class="calibre16">``` <span class="token1">{</span>hkcms<span class="token1">:</span>prenext type<span class="token">=</span><span class="token4">"pre"</span> len<span class="token">=</span><span class="token4">"10"</span> dot<span class="token">=</span><span class="token4">"...."</span><span class="token1">}</span> <span class="token"><</span>div class<span class="token">=</span><span class="token4">"text-primary"</span><span class="token">></span><span class="token"><</span>a href<span class="token">=</span><span class="token4">"{$item.url}"</span><span class="token">></span><span class="token1">{</span>$item<span class="token1">.</span>title<span class="token1">}</span><span class="token"><</span><span class="token">/</span>a<span class="token">></span><span class="token"><</span><span class="token">/</span>div<span class="token">></span> <span class="token1">{</span><span class="token2">else</span> <span class="token">/</span><span class="token1">}</span> <span class="token"><</span>div<span class="token">></span>没有上一篇了<span class="token"><</span><span class="token">/</span>div<span class="token">></span> <span class="token1">{</span><span class="token">/</span>hkcms<span class="token1">:</span>prenext<span class="token1">}</span> ``` ``` ## 参数 参数名称可选值默认值是否必填说明typepre/next-是pre=调取上一篇,next调取下一篇id-item-指定变量名,例如id='obj',模板调用如:{$item.action} 变成 {$obj.action}field-title-这里指定后结合len、dot参数生成len---限制标题长度dot---超出的标题尾部拼接字符num---设置获取条数,默认是单条## 参数说明 - type,只能填写pre(上一篇)、next(下一篇) 获取上一篇数据 ``` <pre class="calibre16">``` <span class="token1">{</span>hkcms<span class="token1">:</span>prenext type<span class="token">=</span><span class="token4">"pre"</span><span class="token1">}</span> <span class="token"><</span>a href<span class="token">=</span><span class="token4">"{$item.url}"</span><span class="token">></span><span class="token1">{</span>$item<span class="token1">.</span>title<span class="token1">}</span><span class="token"><</span><span class="token">/</span>a<span class="token">></span> <span class="token1">{</span><span class="token">/</span>hkcms<span class="token1">:</span>prenext<span class="token1">}</span> ``` ``` - id,指定变量,默认是$item,如下改成obj后写法 ``` <pre class="calibre16">``` <span class="token1">{</span>hkcms<span class="token1">:</span>prenext type<span class="token">=</span><span class="token4">"pre"</span> id<span class="token">=</span><span class="token4">"obj"</span><span class="token1">}</span> <span class="token"><</span>a href<span class="token">=</span><span class="token4">"{$obj.url}"</span><span class="token">></span><span class="token1">{</span>$obj<span class="token1">.</span>title<span class="token1">}</span><span class="token"><</span><span class="token">/</span>a<span class="token">></span> <span class="token1">{</span><span class="token">/</span>hkcms<span class="token1">:</span>prenext<span class="token1">}</span> ``` ``` - field,这里结合len、dot参数,如下:设置标题长度为10超出的加上“.....” ``` <pre class="calibre16">``` <span class="token1">{</span>hkcms<span class="token1">:</span>prenext type<span class="token">=</span><span class="token4">"pre"</span> len<span class="token">=</span><span class="token4">"10"</span> dot<span class="token">=</span><span class="token4">"....."</span><span class="token1">}</span> <span class="token"><</span>div<span class="token">></span><span class="token1">{</span>$item<span class="token1">.</span>title<span class="token1">}</span><span class="token"><</span><span class="token">/</span>div<span class="token">></span> <span class="token1">{</span><span class="token">/</span>hkcms<span class="token1">:</span>prenext<span class="token1">}</span> ``` ``` 效果 ``` <pre class="calibre16">``` 演示数据演示数据数据<span class="token1">.</span><span class="token1">.</span><span class="token1">.</span><span class="token1">.</span><span class="token1">.</span> ``` ``` `num` 数量属性,可获取多条上一篇或下一篇数据 ``` <pre class="calibre16">``` <span class="token1">{</span>hkcms<span class="token1">:</span>prenext type<span class="token">=</span><span class="token4">"pre"</span> num<span class="token">=</span><span class="token4">"10"</span> len<span class="token">=</span><span class="token4">"10"</span> dot<span class="token">=</span><span class="token4">"...."</span><span class="token1">}</span> <span class="token"><</span>a href<span class="token">=</span><span class="token4">"{$item['url']}"</span><span class="token">></span><span class="token1">{</span>$item<span class="token1">[</span><span class="token4">'title'</span><span class="token1">]</span><span class="token1">}</span><span class="token"><</span><span class="token">/</span>a<span class="token">></span> <span class="token1">{</span><span class="token2">else</span> <span class="token">/</span><span class="token1">}</span> <span class="token"><</span>div<span class="token">></span>没有上一篇了<span class="token"><</span><span class="token">/</span>div<span class="token">></span> <span class="token1">{</span><span class="token">/</span>hkcms<span class="token1">:</span>prenext<span class="token1">}</span> ``` ``` ****另外可以增加{else /},来判断在没有上一篇时的处理,如下**** ``` <pre class="calibre20">``` <span class="token1">{</span>hkcms<span class="token1">:</span>prenext type<span class="token">=</span><span class="token4">"pre"</span><span class="token1">}</span> <span class="token"><</span>div class<span class="token">=</span><span class="token4">"text-primary"</span><span class="token">></span><span class="token"><</span>a href<span class="token">=</span><span class="token4">"{$item['url']}"</span><span class="token">></span><span class="token1">{</span>$item<span class="token1">[</span><span class="token4">'title'</span><span class="token1">]</span><span class="token1">}</span><span class="token"><</span><span class="token">/</span>a<span class="token">></span><span class="token"><</span><span class="token">/</span>div<span class="token">></span> <span class="token1">{</span><span class="token2">else</span> <span class="token">/</span><span class="token1">}</span> <span class="token"><</span>div<span class="token">></span>没有上一篇了<span class="token"><</span><span class="token">/</span>div<span class="token">></span> <span class="token1">{</span><span class="token">/</span>hkcms<span class="token1">:</span>prenext<span class="token1">}</span> ``` ```