Sample Blog Listing With URL Map, Pagination, Tag&Cat Search

Description

Sample Blog Listing With URL Mapping for more friendly URL building, pulling a paginated listing using the new dotContent tool, and Tag and Category search filtering.  I am submitting blog detail code and RSS code as well.

Image

Sample Blog Listing With URL Map, Pagination, Tag&Cat Search

Code

${esc.hash}set(${esc.dollar}catVar=${esc.dollar}request.getParameter("cat"))
${esc.hash}set(${esc.dollar}tagVar=${esc.dollar}request.getParameter("tag"))
${esc.hash}set(${esc.dollar}searchVar=${esc.dollar}request.getParameter("blogSearch"))

${esc.hash}set(${esc.dollar}nowsers= ${esc.dollar}date.format('yyyyMMddHHmmss', ${esc.dollar}date.getDate()))

${esc.hash}set(${esc.dollar}_qk = "+structureName:Blog +(conhost:48190c8c-42c4-46af-8d1a-0cd5db894797 conhost:SYSTEM_HOST)")

${esc.hash}if(${esc.dollar}UtilMethods.isSet(${esc.dollar}searchVar))
  ${esc.hash}set(${esc.dollar}_qk = ${esc.dollar}_qk + "+(Blog.title:*${esc.dollar}searchVar* || Blog.body:*${esc.dollar}searchVar*)")
${esc.hash}end

${esc.hash}if(${esc.dollar}UtilMethods.isSet(${esc.dollar}catVar))
  ${esc.hash}set(${esc.dollar}_qk = ${esc.dollar}_qk + "+(categories:${esc.dollar}catVar)")
${esc.hash}end

${esc.hash}if(${esc.dollar}UtilMethods.isSet(${esc.dollar}tagVar))
  ${esc.hash}set(${esc.dollar}_qk = ${esc.dollar}_qk + "+Blog.tags:*${esc.dollar}tagVar*")
${esc.hash}end

${esc.hash}if(${esc.dollar}request.getParameter("page"))
  ${esc.hash}set(${esc.dollar}pageNumber = ${esc.dollar}math.toInteger(${esc.dollar}request.getParameter("page")))
${esc.hash}else
  ${esc.hash}set(${esc.dollar}pageNumber = 1)
${esc.hash}end

${esc.hash}set(${esc.dollar}numberToPull = 5)

${esc.hash}set(${esc.dollar}mypagelist = ${esc.dollar}dotcontent.pullPerPage("${esc.dollar}{_qk}",${esc.dollar}{pageNumber},${esc.dollar}{numberToPull},"Blog.sysPublishDate desc"))

<div class="page-title">
  ${esc.hash}if(${esc.dollar}UtilMethods.isSet(${esc.dollar}catVar))
    <a class="rss-button" href="/blogs/rss.dot?cat=${esc.dollar}catVar">RSS</a>
  ${esc.hash}else
    <a class="rss-button" href="/blogs/rss.dot">RSS</a>
  ${esc.hash}end
  <h2>Insight Blog</h2>
  <p class="search-string">
    ${esc.hash}if(${esc.dollar}UtilMethods.isSet(${esc.dollar}searchVar))
      Search Results for: <span>"${esc.dollar}searchVar"</span>
    ${esc.hash}end
    ${esc.hash}if(${esc.dollar}UtilMethods.isSet(${esc.dollar}catVar))
      Filter by: <span>"${esc.dollar}catVar"</span>
    ${esc.hash}end
    ${esc.hash}if(${esc.dollar}UtilMethods.isSet(${esc.dollar}tagVar))
      Tagged by: <span>"${esc.dollar}tagVar"</span>
    ${esc.hash}end
  </p>
</div>

<ul class="news-listing">
  ${esc.hash}set(${esc.dollar}contentCount = (${esc.dollar}pageNumber - 1) * ${esc.dollar}numberToPull)
  ${esc.hash}foreach(${esc.dollar}con in ${esc.dollar}mypagelist)
    ${esc.hash}set(${esc.dollar}contentCount = ${esc.dollar}contentCount + 1)
    <li>
      ${esc.hash}editContentlet(${esc.dollar}con.inode)
      <h3><a href="/blog/${esc.dollar}con.urlTitle">${esc.dollar}!{con.title}</a></h3>
      <span class="byline">${esc.dollar}!con.author</span>
      <time datetime="${esc.dollar}date.format('yyyy-MM-dd',${esc.dollar}!con.sysPublishDate)T${esc.dollar}date.format('hh:mm:ss',${esc.dollar}!con.sysPublishDate)">
        ${esc.dollar}date.format('MMMM dd, yyyy',${esc.dollar}con.sysPublishDate),
        ${esc.hash}if(${esc.dollar}con.commentscount > 0)
          ${esc.dollar}con.commentscount Comments
        ${esc.hash}else
          No Comments
        ${esc.hash}end
      </time>
      <p>${esc.dollar}UtilMethods.prettyShortenString("${esc.dollar}con.body", 200)</p>
    </li>
  ${esc.hash}end
</ul>

<div class="pagination">
  <div style="float:left;">
    ${esc.hash}if(${esc.dollar}mypagelist.previousPage)
      ${esc.hash}set(${esc.dollar}prevPage= ${esc.dollar}pageNumber - 1)
      ${esc.hash}if(${esc.dollar}UtilMethods.isSet(${esc.dollar}searchVar))
        <a href="/blogs/index.dot?page=${esc.dollar}prevPage&blogSearch=${esc.dollar}searchVar">
      ${esc.hash}elseif(${esc.dollar}UtilMethods.isSet(${esc.dollar}catVar))
        <a href="/blogs/index.dot?page=${esc.dollar}prevPage&cat=${esc.dollar}catVar">
      ${esc.hash}elseif(${esc.dollar}UtilMethods.isSet(${esc.dollar}tagVar))
        <a href="/blogs/index.dot?page=${esc.dollar}prevPage&tag=${esc.dollar}tagVar">
      ${esc.hash}else
        <a href="/blogs/index.dot?page=${esc.dollar}prevPage">
      ${esc.hash}end
      &${esc.hash}x25C0; Previous</a>
    ${esc.hash}end
  </div>
  <div style="float:right;">
    ${esc.hash}if(${esc.dollar}mypagelist.nextPage)
      ${esc.hash}set(${esc.dollar}nextPage= ${esc.dollar}pageNumber + 1)
      ${esc.hash}if(${esc.dollar}UtilMethods.isSet(${esc.dollar}searchVar))
        <a href="/blogs/index.dot?page=${esc.dollar}nextPage&blogSearch=${esc.dollar}searchVar">
      ${esc.hash}elseif(${esc.dollar}UtilMethods.isSet(${esc.dollar}catVar))
        <a href="/blogs/index.dot?page=${esc.dollar}nextPage&cat=${esc.dollar}catVar">
      ${esc.hash}elseif(${esc.dollar}UtilMethods.isSet(${esc.dollar}tagVar))
        <a href="/blogs/index.dot?page=${esc.dollar}nextPage&tag=${esc.dollar}tagVar">
      ${esc.hash}else
        <a href="/blogs/index.dot?page=${esc.dollar}nextPage">
      ${esc.hash}end
      Next &${esc.hash}x25B6;</a>
    ${esc.hash}end
  </div>
  <div class="clear"></div>
</div>