smarty分页程序,模板小改进

作者 : admin 于 2009-07-27 15:11:04 标签: ,
2009
07-27

增加了:跳转到第几页的功能

模板部分

  1. <div id="page">
  2. <table>
  3.     <tr>
  4.     <td>
  5. 共{{$page.count}}条数据 每页{{$page.pagesize}}条  共{{$page.pagecount}}页 当前第{{$page.page}}页
  6.                 <!-- 新加的跳转功能  start -->
  7.                 跳转到第
  8.                 <select onchange="window.location.href='{{$page.baseurl}}&page='+this.options[this.selectedIndex].value">
  9.                 {{section name=pagejump loop=4 start=0 step=1 max=4}}
  10.                 <option value="{{$smarty.section.pagejump.index+1}}">{{$smarty.section.pagejump.index+1}}</option>
  11.                 {{/section}}
  12.                 </select> 页
  13.                 <!-- 新加的跳转功能  start -->
  14. </td>
  15. <td>
  16. {{if $page.pagecount>1}}
  17. {{if $page.first eq 1}}
  18. <a href="{{$page.baseurl}}">首页</a>
  19. {{else}}
  20. 首页
  21. {{/if}}
  22. {{if $page.pre eq 1}}
  23. <a href="{{$page.baseurl}}&page={{$page.page-1}}">上一页</a>
  24. {{else}}
  25. 上一页
  26. {{/if}}
  27. {{foreach from=$page.pagelist item=vols}}
  28.     {{if ($vols.page > 0 ) && ($vols.page < = $page.pagecount) }}
  29. {{if $vols.link eq 1}}
  30. <a href="{{$page.baseurl}}&page={{$vols.page}}">[{{$vols.page}}]
  31. {{else}}
  32. [{{$vols.page}}]
  33. {{/if}}
  34. {{/if}}
  35. {{/foreach}}
  36. {{if $page.next eq 1}}
  37. <a href="{{$page.baseurl|default:"?"}}&page={{$page.page+1}}">下一页</a>
  38. {{else}}
  39. 下一页
  40. {{/if}}
  41. {{if $page.last eq 1}}
  42. <a href="{{$page.baseurl|default:"?"}}&page={{$page.pagecount}}">尾页</a>
  43. {{else}}
  44. 尾页
  45. {{/if}}
  46. {{/if}}
  47. </td>
  48. </tr>
  49. </table>
  50. </div>

其实我在做的时候又出现个问题,如果是url重写了,如何来做这个baseurl变量。问题解决方法是,把url当做模板,比如/blog/index/%d

发表评论




XHTML:你可以使用的标签: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

(若看不到验证码,请重新加载页面。)