Maison >php教程 >php手册 >dedecms调用标签总结(二)

dedecms调用标签总结(二)

WBOY
WBOYoriginal
2016-12-05 13:26:241200parcourir

6. 列表调用

首页:

<span style="color: #000000">{dede:arclist row='10' titlelen='24' typeid='2' orderby='pubdate'}
    </span><span style="color: #0000ff"><span style="color: #800000">li</span><span style="color: #0000ff">></span>
        <span style="color: #0000ff"><span style="color: #800000">a </span><span style="color: #ff0000">href</span><span style="color: #0000ff">="[field:arcurl/]"</span><span style="color: #ff0000"> title</span><span style="color: #0000ff">="[field:title/]"</span><span style="color: #0000ff">></span>
            <span style="color: #0000ff"><span style="color: #800000">img </span><span style="color: #ff0000">src</span><span style="color: #0000ff">="[field:litpic/]"</span><span style="color: #ff0000"> alt</span><span style="color: #0000ff">="[field:title/]"</span><span style="color: #0000ff">></span>
            <span style="color: #0000ff"><span style="color: #800000">h4</span><span style="color: #0000ff">></span>[field:title/]<span style="color: #0000ff"></span><span style="color: #800000">h4</span><span style="color: #0000ff">></span>
        <span style="color: #0000ff"></span><span style="color: #800000">a</span><span style="color: #0000ff">></span>
    <span style="color: #0000ff"></span><span style="color: #800000">li</span><span style="color: #0000ff">></span><span style="color: #000000">
{/dede:arclist}</span></span></span></span></span>

(1). row='10' 表示调用十项,最多显示十项。

(2). titlelen='24' 表示标题最多显示 24 个字节,对于常用字, utf-8 的格式下,每一个汉字占三个字节,英文和数字分别占用一个字节。

(3). typeid='2' 是栏目 id 为 2。

(4). orderby='pubdate' 表示按照发布的时间顺序排序,最后发布的文章排在最前面。

列表页:

<span style="color: #000000">{dede:list pagesize='12'}
</span><span style="color: #0000ff"><span style="color: #800000">li</span><span style="color: #0000ff">></span>
    <span style="color: #0000ff"><span style="color: #800000">a </span><span style="color: #ff0000">href</span><span style="color: #0000ff">="[field:arcurl/]"</span><span style="color: #ff0000"> title</span><span style="color: #0000ff">="[field:title/]"</span><span style="color: #0000ff">></span>
        <span style="color: #0000ff"><span style="color: #800000">img </span><span style="color: #ff0000">src</span><span style="color: #0000ff">="[field:litpic/]"</span><span style="color: #ff0000"> alt</span><span style="color: #0000ff">="[field:title/]"</span><span style="color: #0000ff">></span>
        <span style="color: #0000ff"><span style="color: #800000">h4</span><span style="color: #0000ff">></span>[field:title/]<span style="color: #0000ff"></span><span style="color: #800000">h4</span><span style="color: #0000ff">></span>
    <span style="color: #0000ff"></span><span style="color: #800000">a</span><span style="color: #0000ff">></span>
<span style="color: #0000ff"></span><span style="color: #800000">li</span><span style="color: #0000ff">></span><span style="color: #000000">
{/dede:list}</span></span></span></span></span>

上面是最简单的列表调用方式。

(1). pagesize='12' 指明调用 12 项,也就是说最多能显示 12 项。

(2). [field:arcurl/] 调用链接。

(3). [field:title/] 调用标题。

(4). [field:litpic/] 调用缩略图。

列表页之所以不需要加上 id,是因为栏目管理中列表模板已经选定了需要的模板,在该模板下调用不需要指明 id。

链接,标题,缩略图使用频率较高,在内容页的调用方法稍有不同,原因是它们的外面没有嵌套 {dede:...} 之类的标签。调用方法分别为:{dede:field.arcurl/}, {dede:field.title/},{dede:field.litpic/}。

 

7. 分页

官方手册中的分页为:

{dede:pagelist listsize='3' listitem='index pre pageno next end option'/}

官方解释:

listsize=3 表示 [1][2][3] 这些项的长度 x 2;

index 首页

pre 上一页

pageno 页码

next 下一页

end 末页

option 下拉跳转框

通过实际项目中得出的结论可知:listsize=3 表示 [1][2][3] 这些项的长度 x 2,而是[1][2][3] 这些项的长度 x 2 + 1。

我的分页为:

{dede:pagelist listsize='2' listitem='index pageno end option'/}

我的列表一共 16 项,每一页 3 项,5 页显示不完全,最后一页显示 1 项。

点击末页时,会全部展示:

我没有使用 pre(上一页)和 next(下一页) 两个字段,这两个字段意义不大。

这里附上自定义的样式:

<span style="color: #800000">.pagination-wrap </span>{<span style="color: #ff0000">
    margin-top</span>:<span style="color: #0000ff"> 30px</span>;<span style="color: #ff0000">
    text-align</span>:<span style="color: #0000ff"> center</span>;
}<span style="color: #800000">
.pagination </span>{<span style="color: #ff0000">
    display</span>:<span style="color: #0000ff"> inline-block</span>;<span style="color: #ff0000">
    text-align</span>:<span style="color: #0000ff"> center</span>;
}<span style="color: #800000">
.pagination:before,
.pagination:after </span>{<span style="color: #ff0000">
    display</span>:<span style="color: #0000ff"> table</span>;<span style="color: #ff0000">
    content</span>:<span style="color: #0000ff"> ""</span>;
}<span style="color: #800000">
.pagination:after </span>{<span style="color: #ff0000"> clear</span>:<span style="color: #0000ff"> both</span>; }<span style="color: #800000">
.pagination </span>{<span style="color: #ff0000">
    display</span>:<span style="color: #0000ff"> inline-block</span>;<span style="color: #ff0000">
    text-align</span>:<span style="color: #0000ff"> center</span>;
}
<span style="color: #008000">/*</span><span style="color: #008000">根据dedecms模板需要,更改下面样式</span><span style="color: #008000">*/</span><span style="color: #800000">
.pagination > li </span>{<span style="color: #ff0000">
    float</span>:<span style="color: #0000ff"> left</span>;<span style="color: #ff0000">
    display</span>:<span style="color: #0000ff"> block</span>;<span style="color: #ff0000">
    margin-left</span>:<span style="color: #0000ff"> -1px</span>; <span style="color: #008000">/*</span><span style="color: #008000">消除两个 a 在一起时引起的双倍左外边距</span><span style="color: #008000">*/</span><span style="color: #ff0000">
    height</span>:<span style="color: #0000ff"> 30px</span>;<span style="color: #ff0000">
    line-height</span>:<span style="color: #0000ff"> 28px</span>;<span style="color: #ff0000">
    padding-right</span>:<span style="color: #0000ff"> 28px</span>;<span style="color: #ff0000">
    padding-left</span>:<span style="color: #0000ff"> 28px</span>;<span style="color: #ff0000">
    border</span>:<span style="color: #0000ff"> 1px solid #ddd</span>;    
}<span style="color: #800000">
.pagination > li:first-child </span>{<span style="color: #ff0000">
    margin-left</span>:<span style="color: #0000ff"> 0</span>; <span style="color: #008000">/*</span><span style="color: #008000">第一个 li 不需要消除左外边距</span><span style="color: #008000">*/</span><span style="color: #ff0000">
    border-top-left-radius</span>:<span style="color: #0000ff"> 5px</span>;<span style="color: #ff0000">
    border-bottom-left-radius</span>:<span style="color: #0000ff"> 5px</span>;
}<span style="color: #800000">
.pagination > li:last-child </span>{<span style="color: #ff0000">
    border-top-right-radius</span>:<span style="color: #0000ff"> 5px</span>;<span style="color: #ff0000">
    border-bottom-right-radius</span>:<span style="color: #0000ff"> 5px</span>;
}<span style="color: #800000">
.pagination > li > a </span>{<span style="color: #ff0000">
    display</span>:<span style="color: #0000ff"> block</span>;<span style="color: #ff0000">
    width</span>:<span style="color: #0000ff"> 100%</span>;<span style="color: #ff0000">
    height</span>:<span style="color: #0000ff"> 100%</span>;<span style="color: #ff0000">
    color</span>:<span style="color: #0000ff"> #e04728</span>;<span style="color: #ff0000">
    background-color</span>:<span style="color: #0000ff"> #fff</span>;<span style="color: #ff0000">
    padding-right</span>:<span style="color: #0000ff"> 15px</span>;<span style="color: #ff0000">
    padding-left</span>:<span style="color: #0000ff"> 15px</span>;
}<span style="color: #800000">
.pagination > li </span>{<span style="color: #ff0000">
    z-index</span>:<span style="color: #0000ff"> 3</span>;<span style="color: #ff0000">
    cursor</span>:<span style="color: #0000ff"> default</span>;<span style="color: #ff0000">
    color</span>:<span style="color: #0000ff"> #e04728</span>;
}<span style="color: #800000">
.pagination > li.thisclass </span>{<span style="color: #ff0000">
    z-index</span>:<span style="color: #0000ff"> 3</span>;<span style="color: #ff0000">
    color</span>:<span style="color: #0000ff"> #fff</span>;<span style="color: #ff0000">
    cursor</span>:<span style="color: #0000ff"> default</span>;<span style="color: #ff0000">
    background-color</span>:<span style="color: #0000ff"> #e04728</span>;<span style="color: #ff0000">
    border-color</span>:<span style="color: #0000ff"> #e04728</span>;
}<span style="color: #800000">
.pagination > li > select </span>{<span style="color: #ff0000">
    display</span>:<span style="color: #0000ff"> inline-block</span>;<span style="color: #ff0000">
    margin-left</span>:<span style="color: #0000ff"> -1px</span>; <span style="color: #008000">/*</span><span style="color: #008000">消除两个 a 在一起时引起的双倍左外边距</span><span style="color: #008000">*/</span><span style="color: #ff0000">
    border</span>:<span style="color: #0000ff"> 1px solid #ddd</span>;<span style="color: #ff0000">
    height</span>:<span style="color: #0000ff"> 30px</span>;<span style="color: #ff0000">
    line-height</span>:<span style="color: #0000ff"> 28px</span>;<span style="color: #ff0000">
    padding-right</span>:<span style="color: #0000ff"> 28px</span>;<span style="color: #ff0000">
    padding-left</span>:<span style="color: #0000ff"> 28px</span>;<span style="color: #ff0000">
    color</span>:<span style="color: #0000ff"> #e04728</span>;
}<span style="color: #800000">    
.pagination > li > select option </span>{<span style="color: #ff0000">
    display</span>:<span style="color: #0000ff"> block</span>;<span style="color: #ff0000">
    text-align</span>:<span style="color: #0000ff"> center</span>;<span style="color: #ff0000">
    padding-top</span>:<span style="color: #0000ff"> 6px</span>;<span style="color: #ff0000">
    padding-bottom</span>:<span style="color: #0000ff"> 6px</span>;
}<span style="color: #800000">
.pagination > li > select option[selected] </span>{<span style="color: #ff0000">
    color</span>:<span style="color: #0000ff"> #fff</span>;<span style="color: #ff0000">
    background-color</span>:<span style="color: #0000ff"> #e04728</span>;
}<span style="color: #800000">
.pagination > li > select option:hover </span>{<span style="color: #ff0000"> background-color</span>:<span style="color: #0000ff"> #eee</span>; }
<span style="color: #008000">//</span><span style="color: #008000"> dedecms 模板下新增脚本</span><span style="color: #008000">
//</span><span style="color: #008000"> 去除分页时 select 的宽度</span>
$(".pagination > li > select").css("width", "auto"<span style="color: #000000">);
</span><span style="color: #008000">//</span><span style="color: #008000"> 对 li 没有 select 子元素时,设置样式</span>
$(".pagination > li:has(select)"<span style="color: #000000">).css({
    paddingRight: </span>0<span style="color: #000000">,
    paddingLeft: </span>0<span style="color: #000000">,
    border: </span>"none"<span style="color: #000000">
});
$(</span>".pagination > li:has(a)"<span style="color: #000000">).css({
    paddingRight: </span>0<span style="color: #000000">,
    paddingLeft: </span>0<span style="color: #000000">
});
$(</span>".pagination > li.thisclass + li").css("marginLeft", 0);

 

 

8. 多级栏目调用

栏目及其子栏目如下:

以我自己的实例为例,调用指定栏目下的全部二级栏目

<span style="color: #0000ff"><span style="color: #800000">ul </span><span style="color: #ff0000">class</span><span style="color: #0000ff">="content"</span><span style="color: #ff0000"> id</span><span style="color: #0000ff">="categoriesList"</span><span style="color: #0000ff">></span><span style="color: #000000">
    {dede:channelartlist typeid='3' row='1' channelid='17' addfields='product'}
        {dede:channel type='son' noself='yes'}
        </span><span style="color: #0000ff"><span style="color: #800000">li</span><span style="color: #0000ff">><span style="color: #800000">a </span><span style="color: #ff0000">href</span><span style="color: #0000ff">="[field:typelink/]"</span><span style="color: #ff0000"> title</span><span style="color: #0000ff">="[field:typename/]"</span><span style="color: #0000ff">></span>[field:typename/]<span style="color: #0000ff"></span><span style="color: #800000">a</span><span style="color: #0000ff">></span><span style="color: #800000">li</span><span style="color: #0000ff">></span><span style="color: #000000">
        {/dede:channel}
    {/dede:channelartlist}
</span><span style="color: #0000ff"></span><span style="color: #800000">ul</span><span style="color: #0000ff">></span></span></span></span>

(1). typeid='3' 是要指定的栏目的 id 。

(2). row='1' 表示循环一次(我试过如果不设置 row 的值的话,会重复调用13次,因为我这里它的二级子栏目为 13 个)

(3). channelid='17' 表示自定义内容模型的 id 号

(4). addfields='product' 表示自定义内容模型的识别 id

(5). type='son' 表示为其指定栏目的子栏目。

 

9. 当前栏目的高亮显示

栏目的高亮显示,一般是把当前栏目的字体变成不同于其他栏目的颜色,或者对其添加不同于其他栏目的背景颜色。在 dedecms 里分两种情况讨论:

(1). 对于导航,一个导航栏目下可能拥有多个二级子栏目,当该页面属于该栏目的子栏目时,这个栏目也需要高亮显示。这里使用 dedecms 官方文档里的介绍方法:

currentstyle="<span style="color: #0000ff"><span style="color: #800000">li</span><span style="color: #0000ff">><span style="color: #800000">a </span><span style="color: #ff0000">href</span><span style="color: #0000ff">='~typelink~' </span><span style="color: #ff0000">class</span><span style="color: #0000ff">='active'</span><span style="color: #0000ff">></span>~typename~<span style="color: #0000ff"></span><span style="color: #800000">a</span><span style="color: #0000ff">></span><span style="color: #800000">li</span><span style="color: #0000ff">></span>"</span></span>

具体查看 http://www.cnblogs.com/xinjie-just/p/5985455.html 第三条。

(2). 对于二级栏目,使用 js 为其添加高亮的功能,更简单些。

以我自己的实例说明:

<span style="color: #0000ff"><span style="color: #800000">ul </span><span style="color: #ff0000">class</span><span style="color: #0000ff">="content"</span><span style="color: #ff0000"> id</span><span style="color: #0000ff">="categoriesList"</span><span style="color: #0000ff">></span>
    <span style="color: #0000ff"><span style="color: #800000">li</span><span style="color: #0000ff">><span style="color: #800000">a </span><span style="color: #ff0000">href</span><span style="color: #0000ff">="#"</span><span style="color: #ff0000"> title</span><span style="color: #0000ff">="木质防火门"</span><span style="color: #0000ff">></span>木质防火门<span style="color: #0000ff"></span><span style="color: #800000">a</span><span style="color: #0000ff">></span><span style="color: #800000">li</span><span style="color: #0000ff">></span>
    <span style="color: #0000ff"><span style="color: #800000">li</span><span style="color: #0000ff">><span style="color: #800000">a </span><span style="color: #ff0000">href</span><span style="color: #0000ff">="#"</span><span style="color: #ff0000"> title</span><span style="color: #0000ff">="钢质防火门"</span><span style="color: #0000ff">></span>钢质防火门<span style="color: #0000ff"></span><span style="color: #800000">a</span><span style="color: #0000ff">></span><span style="color: #800000">li</span><span style="color: #0000ff">></span>
    <span style="color: #0000ff"><span style="color: #800000">li</span><span style="color: #0000ff">><span style="color: #800000">a </span><span style="color: #ff0000">href</span><span style="color: #0000ff">="#"</span><span style="color: #ff0000"> title</span><span style="color: #0000ff">="钢木质防火门"</span><span style="color: #0000ff">></span>钢木质防火门<span style="color: #0000ff"></span><span style="color: #800000">a</span><span style="color: #0000ff">></span><span style="color: #800000">li</span><span style="color: #0000ff">></span>
    <span style="color: #0000ff"><span style="color: #800000">li</span><span style="color: #0000ff">><span style="color: #800000">a </span><span style="color: #ff0000">href</span><span style="color: #0000ff">="#"</span><span style="color: #ff0000"> title</span><span style="color: #0000ff">="固定式防火窗"</span><span style="color: #0000ff">></span>固定式防火窗<span style="color: #0000ff"></span><span style="color: #800000">a</span><span style="color: #0000ff">></span><span style="color: #800000">li</span><span style="color: #0000ff">></span>
<span style="color: #0000ff"></span><span style="color: #800000">ul</span><span style="color: #0000ff">></span></span></span></span></span></span></span></span></span></span>

方法是,当 a 标签的 href 属性的属性值和页面当前的 url 地址(document.location.href) 能匹配时,就为其添加高亮显示。

<span style="color: #0000ff">var</span> nav = document.getElementById("categoriesList").getElementsByTagName("a"<span style="color: #000000">);
</span><span style="color: #0000ff">for</span>(<span style="color: #0000ff">var</span> i = 0; i ){
    <span style="color: #0000ff">var</span> navLinks = nav[i].getAttribute("href");  <span style="color: #008000">//</span><span style="color: #008000"> 获得链接的 href 属性值</span>
    <span style="color: #0000ff">var</span> pageLink = document.location.href; <span style="color: #008000">//</span><span style="color: #008000"> 获得当前页面的地址</span>
    <span style="color: #0000ff">if</span>(pageLink.indexOf(navLinks) != -1){  <span style="color: #008000">//</span><span style="color: #008000"> 如果没有找到匹配的字符串则返回 -1,不等于 -1,说明匹配到了</span>
        nav[i].className = "active";  <span style="color: #008000">//</span><span style="color: #008000"> 为其添加 active 类</span>
<span style="color: #000000">    }
}</span>
<span style="color: #008000">/*</span><span style="color: #008000">css</span><span style="color: #008000">*/</span><span style="color: #800000">
#categoriesList li a.active </span>{<span style="color: #ff0000">
    color</span>:<span style="color: #0000ff"> #a67650</span>;
}

 

 

10. 上一篇(页)和下一篇(页)

上一篇和下一篇的调用比较简单,官方文档为:

上一篇:{dede:prenext get='pre'/}

下一篇:{dede:prenext get='next'/}

于是,我的 dom 也简单:

<span style="color: #0000ff"><span style="color: #800000">ul </span><span style="color: #ff0000">class</span><span style="color: #0000ff">="pre-next clearfix"</span><span style="color: #0000ff">></span>
    <span style="color: #0000ff"><span style="color: #800000">li </span><span style="color: #ff0000">class</span><span style="color: #0000ff">="pre"</span><span style="color: #0000ff">></span><span style="color: #000000">
    {dede:prenext get='pre'/}
    </span><span style="color: #0000ff"></span><span style="color: #800000">li</span><span style="color: #0000ff">></span>
    <span style="color: #0000ff"><span style="color: #800000">li </span><span style="color: #ff0000">class</span><span style="color: #0000ff">="next"</span><span style="color: #0000ff">></span><span style="color: #000000">
    {dede:prenext get='next'/}
    </span><span style="color: #0000ff"></span><span style="color: #800000">li</span><span style="color: #0000ff">></span>
<span style="color: #0000ff"></span><span style="color: #800000">ul</span><span style="color: #0000ff">></span></span></span></span>
<span style="color: #008000">/*</span><span style="color: #008000">上一篇、下一篇</span><span style="color: #008000">*/</span><span style="color: #800000">
.pre-next li </span>{<span style="color: #ff0000">
    width</span>:<span style="color: #0000ff"> 48%</span>;<span style="color: #ff0000">
    height</span>:<span style="color: #0000ff"> 30px</span>;<span style="color: #ff0000">
    line-height</span>:<span style="color: #0000ff"> 30px</span>;<span style="color: #ff0000">
    font-size</span>:<span style="color: #0000ff"> 14px</span>;<span style="color: #ff0000">
    overflow</span>:<span style="color: #0000ff"> hidden</span>;<span style="color: #ff0000">
    text-overflow</span>:<span style="color: #0000ff"> ellipsis</span>;<span style="color: #ff0000">
    white-space</span>:<span style="color: #0000ff"> nowrap</span>;
}<span style="color: #800000">
.pre-next .pre </span>{<span style="color: #ff0000">
    float</span>:<span style="color: #0000ff"> left</span>;<span style="color: #ff0000">
    text-align</span>:<span style="color: #0000ff"> right</span>;
}<span style="color: #800000">
.pre-next .next </span>{<span style="color: #ff0000">
    float</span>:<span style="color: #0000ff"> right</span>;<span style="color: #ff0000">
    text-align</span>:<span style="color: #0000ff"> left</span>;
}<span style="color: #800000">
.pre-next li a </span>{<span style="color: #ff0000">
    padding-right</span>:<span style="color: #0000ff"> 8px</span>;<span style="color: #ff0000">
    padding-left</span>:<span style="color: #0000ff"> 8px</span>;
}<span style="color: #800000">
.pre-next li a:hover </span>{<span style="color: #ff0000">
    color</span>:<span style="color: #0000ff"> #ef4526</span>;
}

Déclaration:
Le contenu de cet article est volontairement contribué par les internautes et les droits d'auteur appartiennent à l'auteur original. Ce site n'assume aucune responsabilité légale correspondante. Si vous trouvez un contenu suspecté de plagiat ou de contrefaçon, veuillez contacter admin@php.cn