Created
September 20, 2011 15:58
-
-
Save joeyblake/1229496 to your computer and use it in GitHub Desktop.
Articles with pagination Examples
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<cffunction name="newsroom" output="true" access="public" displayname="Newsroom Display"> | |
<cfargument name="section" required="false" default="Firm/Case News" displayname="News Section"> | |
<cfargument name="pagename" required="false" default="newsroom" displayname="News Page"> | |
<cfargument name="perpage" required="false" default="10"> | |
<cf_ccms_getdata_ptsi formid="81" thisthing=true> | |
<cfset startrw = 1> | |
<cfset currentpage = 1> | |
<cfset whereclse = ""> | |
<cfif StructKeyExists(url,'year')> | |
<cfset whereclse = "WHERE articleYear = '#url.year#'"> | |
</cfif> | |
<cfset whereclse = "WHERE articleType = '#arguments.section#' AND Published = 'Yes'"> | |
<cfif StructKeyExists(url,'page')> | |
<cfset startrw = ((url.page-1)*perpage)+1> | |
<cfset currentpage = url.page> | |
</cfif> | |
<cfquery dbtype="query" name="qry"> | |
SELECT * FROM qry #PreserveSingleQuotes(whereclse)# Order By articleDate desc | |
</cfquery> | |
<h1>#qry.ArticleType#</h1> | |
<table> | |
<tr><th style="text-align:left;">Date</th><th style="text-align:left;">Article</th></tr> | |
<cfoutput query="qry" startrow="#startrw#" maxrows=10> | |
<tr><td style="width:100px; vertical-align:top;">#dateFormat(qry.articleDate,'mm/dd/yyyy')#</td><td><a href="/#urlPrep(qry.articleTitle)#/#urlPrep(qry.articleDate)#/#qry.formdatablockid#/#arguments.pagename#.cfm" />#qry.articleTitle#</a></td></tr> | |
</cfoutput> | |
</table> | |
<cfset pgs = Ceiling(qry.recordcount/perpage)> | |
<cfif currentpage GT 1> | |
<cfset startloop = currentpage-1> | |
<cfset pgtoforloop = currentpage+1> | |
<cfelse> | |
<cfset startloop = currentpage> | |
<cfset pgtoforloop = currentpage+2> | |
</cfif> | |
<cfif pgtoforloop GT pgs> | |
<cfset startloop = currentpage-2> | |
<cfset pgtoforloop = pgs> | |
</cfif> | |
<div class="pagenav" style="text-align:right;"> | |
<cfif currentpage GT 1> | |
<a href="/#arguments.pagename#.cfm?<cfif StructKeyExists(url,'year')>year=#url.year#&</cfif>page=#currentpage-1#"><<</a> | |
</cfif> | |
Page: | |
<cfloop from="#startloop#" to="#pgtoforloop#" index=i> | |
<a <cfif currentpage EQ i>style="font-weight:bold;"</cfif> href="/#arguments.pagename#.cfm?<cfif StructKeyExists(url,'year')>year=#url.year#&</cfif>page=#i#">#i#</a><cfif pgtoforloop NEQ i> |</cfif> | |
</cfloop> | |
<cfif currentpage+1 LTE pgs> | |
<a href="/#arguments.pagename#.cfm?<cfif StructKeyExists(url,'year')>year=#url.year#&</cfif>page=#currentpage+1#">>>></a> | |
</cfif> | |
</div> | |
<cfreturn "editurl:'?control=field_display.admin_field_display&formid=81',edittype:'inline' ,editname:'Edit News Or Event'"> | |
</cffunction> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment