OpenCms 带分页的新闻列表
程序员文章站
2023-09-20 11:11:53
<%@ page session="false" import="java.text.simpledateformat,java.uti...
<%@ page session="false" import="java.text.simpledateformat,java.util.date"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ taglib prefix="cms" uri="http://www.opencms.org/taglib/cms"%>
<html>
<head>
<title>测试新闻列表页</title>
<cms:editable/>
</head>
<body>
<!-- param="/test/news_%(number).html|testnews" 中的/test/是指定要显示信息所在的路径,根据实际情况修改,testnews是指定要显示信息的类型 -->
<cms:contentload collector="allinfolderprioritydatedesc" param="/test/news_%(number).html|testnews" preload="true">
<!-- pagesize 即是每页要显示信息的数量 -->
<cms:contentload pagesize="3" pageindex="%(param.pageindex)" pagenavlength="10" editable="true">
<cms:contentinfo var="contentinfo" scope="request" />
<a href="<cms:link><cms:contentshow element="%(opencms.filename)" /></cms:link>" target="_blank"><cms:contentshow element="title" /></a>
<c:set var="strdate"><cms:contentshow element="date" /></c:set>
<%
long longdate = long.valueof(pagecontext.getattribute("strdate").tostring()).longvalue();
simpledateformat sdf = new simpledateformat("yyyy-mm-dd hh:mm");
string createddate = sdf.format(new date(longdate));
out.print(createddate);
%>
</cms:contentload>
<!-- 以下是分页开始 -->
<c:if test="${contentinfo.pageindex>1}">
<a href="<cms:link>${cms:getcmsobject(pagecontext).requestcontext.uri}</cms:link><c:out value="?pageindex=${contentinfo.pageindex-1}"/>">上一页</a>
</c:if>
<c:foreach var="i" begin="${contentinfo.pagenavstartindex}" end="${contentinfo.pagenavendindex}">
<c:choose>
<c:when test="${contentinfo.pageindex==i}">
<font color="red"><c:out value="${i}"/></font>
</c:when>
<c:otherwise>
<a href="<cms:link>${cms:getcmsobject(pagecontext).requestcontext.uri}</cms:link><c:out value="?pageindex=${i}"/>"><c:out value="${i}"/></a>
</c:otherwise>
</c:choose>
</c:foreach>
<c:if test="${contentinfo.pageindex < contentinfo.pagecount}">
<a href="<cms:link>${cms:getcmsobject(pagecontext).requestcontext.uri}</cms:link><c:out value="?pageindex=${contentinfo.pageindex+1}"/>">下一页</a>
</c:if>
</cms:contentload>
</body>
</html>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ taglib prefix="cms" uri="http://www.opencms.org/taglib/cms"%>
<html>
<head>
<title>测试新闻列表页</title>
<cms:editable/>
</head>
<body>
<!-- param="/test/news_%(number).html|testnews" 中的/test/是指定要显示信息所在的路径,根据实际情况修改,testnews是指定要显示信息的类型 -->
<cms:contentload collector="allinfolderprioritydatedesc" param="/test/news_%(number).html|testnews" preload="true">
<!-- pagesize 即是每页要显示信息的数量 -->
<cms:contentload pagesize="3" pageindex="%(param.pageindex)" pagenavlength="10" editable="true">
<cms:contentinfo var="contentinfo" scope="request" />
<a href="<cms:link><cms:contentshow element="%(opencms.filename)" /></cms:link>" target="_blank"><cms:contentshow element="title" /></a>
<c:set var="strdate"><cms:contentshow element="date" /></c:set>
<%
long longdate = long.valueof(pagecontext.getattribute("strdate").tostring()).longvalue();
simpledateformat sdf = new simpledateformat("yyyy-mm-dd hh:mm");
string createddate = sdf.format(new date(longdate));
out.print(createddate);
%>
</cms:contentload>
<!-- 以下是分页开始 -->
<c:if test="${contentinfo.pageindex>1}">
<a href="<cms:link>${cms:getcmsobject(pagecontext).requestcontext.uri}</cms:link><c:out value="?pageindex=${contentinfo.pageindex-1}"/>">上一页</a>
</c:if>
<c:foreach var="i" begin="${contentinfo.pagenavstartindex}" end="${contentinfo.pagenavendindex}">
<c:choose>
<c:when test="${contentinfo.pageindex==i}">
<font color="red"><c:out value="${i}"/></font>
</c:when>
<c:otherwise>
<a href="<cms:link>${cms:getcmsobject(pagecontext).requestcontext.uri}</cms:link><c:out value="?pageindex=${i}"/>"><c:out value="${i}"/></a>
</c:otherwise>
</c:choose>
</c:foreach>
<c:if test="${contentinfo.pageindex < contentinfo.pagecount}">
<a href="<cms:link>${cms:getcmsobject(pagecontext).requestcontext.uri}</cms:link><c:out value="?pageindex=${contentinfo.pageindex+1}"/>">下一页</a>
</c:if>
</cms:contentload>
</body>
</html>
推荐阅读