1.子栏目列表: #foreach($channel in $cms.getChildren($curChannel))
  • $channel.title
  • #end 2.文章的相关属性: 标题: $curArticle.name 副标题: $!{curArticle.viceTitle} 内容: $curArticle.content 摘要: $!{curArticle.summary} 关键字: $!{curArticle.keyword} 来源: $!{curArticle.source} 作者: $!{curArticle.author} 级别: $!{curArticle.grade} 发布日期:$cms.format($curArticle.publishDate) --年-月-日 $cms.format($curArticle.publishDate,"yyyy-MM-dd HH:mm:ss") --年-月-日 时:分:秒 $cms.format($curArticle.publishDate,"MM-dd") --月-日 $cms.format($curArticle.publishDate,"HH:mm:ss") --时:分:秒 扩展属性:$!{curArticle.getProperty("time")} 注:扩展属性中字段填写在内容类型中定义的字段名 3.跳转到第一个下级子栏目 #foreach($channel in $cms.getChildren($curChannel,0,1)) #end 4.栏目主菜单: #foreach($channel in $cms.getTopChildren($rootChannel))
  • $channel.title
  • #end 5.判断是否推荐栏目: #if($curChannel.isSuggest == 1) 6.取当前栏目的前5个子栏目: #foreach($channel in $cms.getChildren($curChannel,1,5)) $channel.title #end 7. 注:$cms.format($content.publishDate)为日期的格式化,可以分为以下几种格式 年-月-日 时:分 $cms.format($article.publishDate,"yyyy-MM-dd hh:mm") 年-月-日 $cms.format($article.publishDate) 月-日 $cms.format($article.publishDate,"MM-dd") 时:分:秒 $cms.format($article.publishDate,"hh:mm:ss") 8.关联模板使用办法(例:子站关联主站某页面) 1>.首先打开主站后台,新建关联模板。 2>设置当前栏目的关联模板为新建的关联模板 3>预览效果为想要获取的那一部分(包含样式)(模板写法:头部和主站当前栏目一致。正文代码为想要获取的那一部分的置标)发布栏目 4>.回到子站,新建模板,除想要替换的部分去除外。其他保持依旧。 5>.添加代码到想要替换的那一部分: src为生成的管理模板文件。可直接访问查看效果。后面长度和宽度可调节 把新建的模板改为当前子站栏目。 完成 9.根据文章类型判断 文章的状态码 撤销6 新稿1 己编2 已签3 己发7 文章类型 type = 0; //类型为链接 type = 1; //类型为文章 type = 2; //类型为产品 type = 3; //类型为文档 type = 4; //类型为转发链接 type = 5; //类型为转发复用 type = 6; //类型为数据库表挂接 10.分页跳转 分页-跳转
    共$totalRows条,分$totalPage页 每页$curChannel.pageCount条 当前$curPage|$totalPage页 首页 #if($curPage>1) 上一页 #else 上一页 #end #if($curPage<$totalPage) 下一页 #else 下一页 #end 尾页 转到
    当页码不能跳转的时候试试把“转到”后面的改成 简化版
    16.取前三篇有图片的 #set($i = 3) #set($j = 0) #foreach($article in $cms.getContentsByChannelName("图片新闻",200)) #if($j < $i) #if($cms.getPictureUrl($article) != "") #if($j == 0)
  • $stringUtil.summary($article.name,23)

    $cms.format($article.publishDate)
  • #else
  • $stringUtil.summary($article.name,23)

    $cms.format($article.publishDate)

    $!{article.summary}

  • #end #set($j = $j + 1) #end #end #end 17.cms8热门文章(需配置cms8访问量代码) #foreach($article in $cmsService.getPageDatas("select * from Content where siteID=$site.id and status=7 and grade=1 order by viewCount desc",1,6))
  • ·$article.title
  • #end 18.cms8取文章内容第一张图片(建议使用获取相关图片置标) #foreach($attimg in $cmsService.getPageDatas("select * from cms_attachment where contentID='$article.id' and (type=1 or type=2) order by sortID ASC",1,1)) 19.判断摘要,为空则取内容的前30个字符 #if($stringUtil.nullFilter($article.summary)!="") $stringUtil.summary($article.summary,30) #else #set($fullArticle=$cmsService.getArticle($article.id)) $stringUtil.summary($cms.clearHtml($fullArticle.content),30) #end 20.取指定栏目下的今日文章(判断相关图片) #foreach($article in $cmsService.getPageDatas("select * from cms_content where to_days(publishdate) = to_days(now()) and parentid = '1049b53de7654e4fb03414a70198c59f'",1,1)) #if($cms.getArticleAttachmentCount($article.id,1)!=0)
  • #summary($article.title 45)

    $!{article.summary}

    $cms.format($article.publishDate)
  • #else
  • #summary($article.title 45)

    $!{article.summary}

    $cms.format($article.publishDate)
  • #end #end 21.判断月份 #if($cms.format($article.publishDate,"MM")=='01') Jan #elseif($cms.format($article.publishDate,"MM")=='02') Feb #elseif($cms.format($article.publishDate,"MM")=='03') Mar #elseif($cms.format($article.publishDate,"MM")=='04') Apr #elseif($cms.format($article.publishDate,"MM")=='05') May #elseif($cms.format($article.publishDate,"MM")=='06') Jun #elseif($cms.format($article.publishDate,"MM")=='07') Jul #elseif($cms.format($article.publishDate,"MM")=='08') Aug #elseif($cms.format($article.publishDate,"MM")=='09') Sep #elseif($cms.format($article.publishDate,"MM")=='10') Oct #elseif($cms.format($article.publishDate,"MM")=='11') Nov #elseif($cms.format($article.publishDate,"MM")=='12') Dec #end 22.带数字分页 #set($prePage=$curPage - 1) #set($leftm=$prePage/5) #set($left=$leftm*5 + 1) #set($right=$leftm*5 + 5) #if($right>$totalPage) #set($right=$totalPage) #end #set($nextPage=$curPage + 1) #set($newPage1 = $left + 5) #set($newPage2 = $left - 1) #if($leftm>0) 首页 #end #if($curPage>1) 上一页 #end #foreach($index in [$left..$right]) #if ($index == $curPage) $index #else $index #end #end #if($curPage<$totalPage) 下一页 #end #if($totalPage > $right) 尾页 #end 23.cms8常用置标汇总 1》路径默认写法 $pathUtil.getSiteUrl($site)/js $pathUtil.getSiteUrl($site)/css $pathUtil.getSiteUrl($site)/images 2》首页获取指定栏目子栏目(首页区别于其他页) #foreach($channel in $cms.getChildrenByName("新闻动态"))
  • $channel.title
  • #end 3》索引页获取指定栏目文章(索引页区别于其他页) #foreach($article in $cms.getContentsByChannelName("新闻动态",50))
  • $cms.format($article.publishDate)#summary($article.name 20)
  • #end 4》标题截取 $stringUtil.summary($article.name,40) 5》父级栏目 $cms.getChannel($curChannel.parentID).title 6》同级栏目 #foreach($channel in $cms.getChildren($cms.getChannel($curChannel.parentID))) $channel.title #end 7》站点名 $site.name 8》索引页显示文章 #foreach($article in $cms.getContents($curChannel,1)) #set ($fullArticle=$cmsService.getArticle($article.id)) $fullArticle.content #end 9》判断相关附件 #if ($cms.getArticleAttachmentCount($curArticle.id, 3)>0)

    相关附件

    #else #end 10》判断新稿 #if( $cms.isNew($article,3) ) 11》判断是否存在子栏目 #if($cms.getChannelCount($channel.id) > 0) 12》判断副标题为空 #if($stringUtil.nullFilter($curArticle.viceTitle) !="") 13》栏目图片(只能取当前栏目的,不能取父级栏目) $curChannel.logo 14《跳转第一篇文章(区别跳转第一个栏目) #foreach($article in $cms.getContents($curChannel,1)) #end 15》取前三个有图片的文章 #set($i = 3) #set($j = 0) #foreach($article in $cms.getContentsByChannelName("学院动态",200)) #if($j < $i) #if($cms.getPictureUrl($article) != "") #if($j == 0)
  • #else
  • #end #set($j = $j + 1) #end #end #end 16》判断相关图片 #if($cms.getPictureUrl($article) != "") 24.取转发类型文章所属栏目名 较早版本cms8 #foreach($article in $cms.getPageContents($curChannel,$curPage)) #if($article.type == '4' || $article.type == '5') #set($fullArticle=$cmsService.getArticle($article.srcContentID)) #set($chl=$cms.getChannel($fullArticle.parentID)) $chl.title #end 后期版本cms8 #foreach($article in $cms.getPageContents($curChannel,$curPage)) #if($article.type == '4' || $article.type == '5') #set($fullArticle=$cms.getSrcContent($article.id)) #set($chl=$cms.getChannel($fullArticle.parentID)) $chl.title #end 25.首页和第二页顶部样式差异处理(缺点:首页除顶部特殊样式以外的文章,会差几条数据,建议顶部显示的条数和每行显示的条数一致时,再使用(例如每页21篇文章,一行3个,建议顶部也只有3个,这样首页除顶部外有18篇,底部不会出现缺少文章的情况,且整页有21篇。第二页正常显示。或者一行一个的,也满足此类样式需求))
    #if($curPage == 1) #foreach($article in $cms.getContents($curChannel,1,1))

    $article.name

    $cms.format($article.publishDate)
    #end #end
    26.最近发布的文章显示 #if( $cms.isNew($article,7) ) 27.置顶文章显示 #if("$!article.isTop" != "0") 28.取内容中前100字 #if($stringUtil.nullFilter($fullArticle.summary)!="") $stringUtil.summary($fullArticle.summary,100) #else $stringUtil.summary($cms.clearHtml($fullArticle.content),100) #end 29.取内容中第一张图片 #set($contentimg="") #foreach($attimg in $cmsService.getPageDatas("select * from cms_attachment where contentID='$fullArticle.id' and (type=1 or type=2) order by sortID ASC",0,5)) #set($contentimg = $cms.getAttachmentUrl($attimg))
    #end 30.取摘要前100字符,如无摘要取内容前100 #if($stringUtil.nullFilter($article.summary)!="") $stringUtil.summary($article.summary,100) #else #set($fullArticle=$cmsService.getArticle($article.id)) $stringUtil.summary($cms.clearHtml($fullArticle.content),100) #end 31.转发或重用类型文章,取摘要前100字符,如无摘要取内容前100 #if($article.type==4||$article.type==5) #set($fullArticle=$cmsService.getArticle($article.srcContentID)) #else #set($fullArticle=$article) #end #if($stringUtil.nullFilter($fullArticle.summary)!="") $stringUtil.summary($fullArticle.summary,100) #else #set($fullArticle=$cmsService.getArticle($fullArticle.id)) $stringUtil.summary($cms.clearHtml($fullArticle.content),100) #end 32.第一取相关图片,取不到取内容中的,再取不到取固定图片 #if($stringUtil.nullFilter($cms.getPictureUrl($article)) != "" )
    #else #if($article.type==4||$article.type==5) #set($fullArticle=$cmsService.getArticle($article.srcContentID)) #else #set($fullArticle=$article) #end #set($tmp=$cmsService.getPageDatas("select * from cms_attachment where contentID='$fullArticle.id' and type=2 order by sortID ASC")) #if($tmp.size() > 0) #foreach($attimg in $cmsService.getPageDatas("select * from cms_attachment where contentID='$fullArticle.id' and type=2 order by sortID ASC",0,5)) #set($contentimg = $cms.getAttachmentUrl($attimg))
    #end #else
    #end #end 33.查询站点创建时间及站点名 cms7 #foreach($site in $cmsService.find("From Site where status=1"))

    站点创建时间:${site.creationDate}     站点名称:${site.name}

    #end 34.cms8上下一篇 $cms.getNextUrl($curArticle)和$cms.getPrevUrl() 35.页面显示当前日期 36.循环文件及多文件 #set($i=0) #foreach($schema in $cms.getTeacherCustomizeSchema($curArticle.id)) #set($i=$i+1)

    $schema.title

    #if($schema.type == 3)
    $schema.prop
    #elseif($schema.type == 5)
    #foreach($file in $schema.getFiles()) #set($cc = $file.url.split("[.]")) #if($cc.get(1) == "mp4")
    #else $file.title
    #end #end
    #else
    $schema.content
    #end
    #end 37.截取文件后缀(特殊符号单独处理,例如.和+默认不需要带中括号) #foreach($doc in $cms.getAttachments($curArticle)) #set($cc = $doc.split("[.]")) #if($cc.get(1) == "mp4")
    #else
  • $doc.name
  • #end #end 38.取子栏目文章数量 #foreach($channel in $cms.getChildren($curChannel)) $cms.getContentCount($channel.id) #end 39.取当前栏目下第一篇文章的所有相关图片,并显示图片名称($attimg.name) #foreach($article in $cms.getContents($curChannel,1)) #foreach($attimg in $cmsService.getPageDatas("select * from cms_attachment where contentID='$article.id' and (type=1 or type=2) order by sortID ASC",1,100))
  • $attimg.name
  • #end #end 40.自动获取当前年份 Copyright © 41.上一个栏目,下一个栏目 下一个同级栏目: #set($g = 2) #foreach($channel in $cms.getChildren($cms.getChannel($curChannel.parentID))) #if($channel.title==$curChannel.title) #foreach($channel in $cms.getChildren($cms.getChannel($curChannel.parentID),$g,1)) < a href="$cms.getUrl($channel)">$channel.title #end #end #set($g=$g+1) #end 上一个同级栏目: #set($g = 0) #foreach($channel in $cms.getChildren($cms.getChannel($curChannel.parentID))) #if($channel.title==$curChannel.title) #foreach($channel in $cms.getChildren($cms.getChannel($curChannel.parentID),$g,1)) < a href="$cms.getUrl($channel)">$channel.title #end #end #set($g=$g+1) #end 42.标题颜色置标: cms7:$article.title_color cms8:$article.titleColor 43.cms8站点对外名称 $site.fullName $site.fullName 44.cms8最新版取指定栏目及其子栏目下的所有文章,判断相关图片和内容图片 #foreach($article in $cmsService.getPageDatas("select * from cms_content where parentID in (select id from cms_channel where parentID='295') and status=7 order by publishDate desc",1,500)) #if($stringUtil.nullFilter($cms.getPictureUrl($article)) != "" )

    $article.title

    查看更多

    #else #if($article.type==4||$article.type==5) #set($fullArticle=$cms.getSrcContent($article.id)) #else #set($fullArticle=$article) #end #set($tmp=$cmsService.getPageDatas("select * from cms_attachment where contentID='$fullArticle.id' and type=2 order by sortID ASC")) #foreach($attimg in $cmsService.getPageDatas("select * from cms_attachment where contentID='$fullArticle.id' and type=2 order by sortID ASC",0,1)) #set($contentimg = $cms.getAttachmentUrl($attimg))

    $fullArticle.name

    查看更多

    #end #end #end 11245#foreach($article in $cms.getPageContents($curChannel,$curPage)) #if($velocityCount == 1)//第一个 肯定是判断==1,这样才能开始样式调用,不要直接想循环出几个列表
    #end #end 46.取全部相关图片 #foreach($pic in $cms.getPictures($curArticle))
  • #end 47.从第二篇符合条件的(article.viceTitle不为空)的开始取,取99 #set($expNum = 0) #set($i = 100) #set($j = 0) #foreach($article in $cms.getContentsByChannelName("团队成员",9999)) #set($i=$i + 1) #if($j < $i) #if($article.viceTitle=="$article.viceTitle") #set($expNum = $expNum + 1) #if($expNum > 1)
    #end #set($j = $j + 1) #end #end #end 48.指定栏目文章数量为0 #if($cms.getContentCountByChannelName("首页")==0)