叶子小小的,碧绿碧绿的,花儿小小的,好可爱。紫红色的玫瑰花在风中翩翩起舞,玫瑰花树枝上还有调皮又可爱的小刺,你可要当心哦!你看,那个大仙人球旁围着8个小仙人球,好像一家人聚在一起,多欢快呀!
简化部分主要是栏目切换时,除子第一个默认栏目,其它的全改成ajax,不再生成静态页,而且通过PHP循环,简化了代码.另外加载更多按钮等也修改了触发形式.
效果图
一,模板
模板中涉及一个函数.get_url_by_typeid2()在这里的说明,点击查看
[html]view plaincopy
- <divclass="containermargin-topover-hidden">
- <divclass="xl12xb12over-hidden">
- <!--切换标签-->
- <styletype="text/css">
- .slideTxtBox{width:100%;text-align:left;}
- .slideTxtBox.hd{height:38px;line-height:27px;position:relative;overflow:hidden}
- .slideTxtBox.hdul{left:10px;float:left;position:absolute;top:3px;height:39px;over-flow:hidden;}
- .slideTxtBox.hdulli{height:40px;float:left;color:#fff;padding:0px7px0px6px;cursor:pointer;}
- .slideTxtBox.hdullia{color:#fff;}
- .slideTxtBox.hdulli.on
- {background:url({dede:global.cfg_templets_skin/}/images/bg5.png)repeat-x;}
- .slideTxtBox.hdulli.ona{color:#555}
- .slideTxtBox.bdul{zoom:1;padding-bottom:50px;display:none;position:relative;min-height:100px}
- .slideTxtBox.bdli{height:24px;line-height:24px;}
- </style>
- <divid="slideTxtBox"class="slideTxtBoxpadding00"style="overflow:visible!important;">
- <!--主导航-->
- <divclass="hdbg-mainpr">
- <ulid="tab"class="border-topborder-mainborder-big">
- <liclass="on"id=""><ahref="javascript:"onclick="javascript:loadMoreApply(1,0);">全部</a></li>
- {dede:channeltype='top'row='50'}
- <liid="tab[field:id/]"><ahref="javascript:"onclick="javascript:change_tab([field:id/]);loadMoreApply(1,[field:id/]);">[field:typename/]</a></li>
- {/dede:channel}
- </ul>
- <spanclass="icon-angle-downtext-whitewidth30padding-left10ibtext-22top7right2bg-main"data-target="#navbar2">
- </span>
- </div>
- <!--下拉导航-->
- <divclass="navbar-bodymargin-top6hiddenib"id="navbar2">
- <ulclass="navnav-inlinenav-menu">
- {dede:channelartlisttypeid="top"row='33'}
- <liclass="{dede:field.active/}">
- <ahref="javascript:"onclick="javascript:change_tab({dede:field.typeid/});loadMoreApply(1,{dede:field.typeid/});">
- {dede:fieldname="typename"/}
- </a>
- </li>
- {/dede:channelartlist}
- </ul>
- </div>
- <divclass="bd"id="slideTxtBox-bd">
- <ulid="0"class="show">
- <!--全部-->
- {dede:arclistrow='2'titlelen='100'orderby='id'}
- <divclass="bg-fffwidth-100ibpr">
- <divclass="xl12padding10">
- <divclass="mediamedia-x">
- <aclass="float-left"href="[field:arcurl/]">
- <imgsrc="[field:litpic/]"width="80"class="radius"alt="[field:title/]">
- </a>
- <divclass="media-body"style="width:900px;height:;">
- <strong>[field:title/]</strong>
- <divstyle="height:5px;"></div>
- <!--点击-->
- <span>
- <spanclass="cursoricon-click"></span>
- <scriptsrc="/plus/count_list.php?view=yes&aid=[field:id/]"type='text/javascript'language="javascript"></script></span>
- <spanid="diggNum[field:id/]"><ahref="javascript:"class="text-bbbtext-16width33"onclick="javascript:postDigg('good',[field:id/])"><spanid="digg[field:id/]"class="icon-heart2"></span></a>[field:goodpost/]
- </span>
- <divstyle="height:12px;"></div>
- <!--所属分类archives-->
- <aclass="buttonbg-graybutton-littleradius-nonemargin-right2text-12"href="javascript:"onclick="javascript:change_tab([field:typeid/]);loadMoreApply(1,[field:typeid/]);">[field:typename/]</a>[field:typeid2function="get_url_by_typeid2(@me)"/]
- </div>
- </div>
- </div>
- <aclass="buttonbg-mainbutton-smallright5text-whiteibpatext-14"href="javascript:;"onclick="showtip('[field:title/]')"style="top:40px">进入小程序</a>
- </div>
- {/dede:arclist}
- <pclass="text-centermargin-bottombottom0rightwidth-100"><aonclick="javascript:loadMoreApply(1,0);"href="javascript:"class="buttonradius-roundedborder-main"id="0data">加载更多</a></p>
- </ul>
- {dede:channeltype='top'row='25'}
- <!--[field:typename/]-->
- <ulid="[field:id/]">
- <pclass="text-centerbottom0margin-bottommargin-big-topwidth-100"><aonclick="javascript:loadMoreApply(1,[field:id/]);"href="javascript:"class="buttonradius-roundedborder-main"id="[field:id/]data">加载更多</a></p>
- </ul>
- {/dede:channel}
- </div>
- </div>
- <!--slideTxtBoxend-->
- <scripttype="text/javascript">
- vartabs=document.getElementById("tab").getElementsByTagName("li");
- vardivs=document.getElementById("slideTxtBox-bd").getElementsByTagName("ul");
- for(vari=0;i<tabs.length;i++){
- tabs[i].onclick=function(){change(this);}
- }
- functionchange(obj){
- for(vari=0;i<tabs.length;i++)
- {
- if(tabs[i]==obj){
- tabs[i].className="on";
- divs[i].className="show";
- }
- else{
- tabs[i].className="";
- divs[i].className="";
- }
- }
- }
- //所属分类切换
- functionchange_tab(typeid){
- $("#tab"+typeid).siblings("li").removeClass("on");
- $("#tab"+typeid).addClass("on");
- $("#"+typeid).siblings("ul").removeClass("show");
- $("#"+typeid).addClass("show");
- }
- </script>
- <!--切换结束-->
- </div>
- </div>
- <scripttype="text/javascript">
- $('.icon-angle-down').each(function(){
- vare=$(this);
- vartarget=e.attr("data-target");
- e.click(function(){
- $(target).toggleClass("hidden");
- });
- });
- varloadConfig={
- url_api:'/plus/list.php',
- //typeid:{dede:fieldname="typeid"/},
- pagesize:2,
- loading:0
- }
- varpage0=2;
- {dede:channeltype='top'row='25'}
- varpage[field:id/]=1;
- {/dede:channel}
- functionloadMoreApply(orderby,typeid){
- $("#navbar2").addClass("hidden");
- eval("page=page"+typeid+";");
- varpagesize=loadConfig.pagesize;
- varurl=loadConfig.url_api,
- data={ajax:'pullload',typeid:typeid,page:page,pagesize:pagesize,orderby:orderby};
- functionajax(url,data){
- $.ajax({url:url,data:data,async:false,type:'GET',dataType:'json',success:function(data){
- addContent(data,typeid);
- }});
- }
- ajax(url,data);
- }
- functionaddContent(rs,typeid){
- if(rs.statu==1){
- vardata=rs.list;
- vartotal=rs.total;
- vararr=[];
- varlength=data.length;
- for(vari=0;i<length;i++){
- arr.push('<divclass="bg-fffwidth-100ibpr">');
- arr.push('<divclass="xl12padding10"><divclass="mediamedia-x"><aclass="float-left"href="'+data[i].arcurl+'"><imgsrc="'+data[i].picname+'"width="80"class="radius"alt="'+data[i].title+'"></a><divclass="media-body"style="width:900px"><strong>'+data[i].title+'</strong><divstyle="height:5px;"></div><span><spanclass="cursoricon-click"></span>'+data[i].click+'</span>');
- arr.push('<spanid="diggNum'+data[i].id+'"><ahref="javascript:"class="text-bbbtext-16"onclick="javascript:postDigg(\&;good\&;,'+data[i].id+');"><spanid="digg'+data[i].id+'"class="icon-heart2"></span></a>'+data[i].goodpost+'</span><divstyle="height:12px;"></div>');
- arr.push('<aclass="buttonbg-graybutton-littleradius-nonemargin-right2text-12"href="javascript:"onclick="javascript:change_tab('+data[i].typeid+');loadMoreApply(1,'+data[i].typeid+');">'+data[i].typename+'</a>'+data[i].typeid2+'</div></div></div><aclass="buttonbg-mainbutton-smallright5text-whiteibpatext-14"href="javascript:;"onclick="showtip(\&;'+data[i].title+'\&;)"style="top:40px">进入小程序</a></div>');
- }
- $('#'+typeid).append(arr.join(''));
- loadConfig.load_num=rs.load_num;
- if(total<page*loadConfig.pagesize||page>loadConfig.load_num){
- //$('#'+typeid).append('<pclass="text-centermargin-top"><ahref="javascript:"class="buttonradius-roundedborder-mainwidth-20"id="'+typeid+'data">没有了!</a></p>');
- $("#"+typeid+"data").html('没有了!');
- }else{
- //$('#'+typeid).append('<pclass="text-centermargin-top"><ahref="javascript:"class="buttonradius-roundedborder-mainwidth-20"id="'+typeid+'data">加载更多</a></p>');
- }
- eval("page"+typeid+"++;");
- }else{
- $("#"+typeid+"data").html('没有了!');
- }
- }
- $(document).ready(function(){
- loadMoreApply(1,0);
- $('.copy-lay.close2').click(function(){
- $('.alert2').hide();
- });
- $('.alert2').click(function(e){
- if($(e.target).parents().hasClass('copy-lay')){
- return;
- }else{
- $(this).hide();
- }
- });
- });
- functionshowtip(title){
- $('#alerttip,#copyBtn').html(title);
- $('.alert2').show();
- }
- </script>
- {dede:sqlsql='Select*from`myppttype`whereid=2'}
- <divclass="alert2alert-copy">
- <divclass="copy-lay"style="[field:other/]">
- <spanclass="close2"></span>
- <divclass="copy"id="copyBtn"></div>
- <divclass="copy-layer-img"style="background:url('[field:pic/]')no-repeat;-o-background-size:contain;background-size:contain;"></div>
- </div>
- </div>
- {/dede:sql}
二,,修改,plus/list.PHP在require_once(dirname(__FILE__)."/../include/common.inc.php");
的下面增加一段
[php]view plaincopy
- if(isset($_GET['ajax'])){
- $typeid=isset($_GET['typeid'])?intval($_GET['typeid']):0;//传递过来的分类ID
- $orderby=isset($_GET['orderby'])?intval($_GET['orderby']):1;
- //print_r($orderby);exit;
- //1id排,2hot排序
- $page=isset($_GET['page'])?intval($_GET['page']):0;//页码
- $pagesize=isset($_GET['pagesize'])?intval($_GET['pagesize']):10;//每页多少条,也就是一次加载多少条数据
- $start=$page>0?($page-1)*$pagesize:0;//数据获取的起始位置。即limit条件的第一个参数。
- $ntime2=gmmktime(0,0,0,gmdate('m'),gmdate('d'),gmdate('Y'));
- $limitday=$ntime2-(40*24*3600);//40天内热文
- $orwheres="senddate>$limitday";
- //$typesql=$typeid?"WHEREtypeid=$typeid":'';
- if($orderby==1){//id降序
- $typesql=$typeid?"WHEREa.arcrank=0anda.typeid=$typeidorCONCAT(',',a.typeid2,',')LIKE'%,".$typeid.",%'":'';
- $typesql3=$typeid?"WHEREarcrank=0andtypeid=$typeidorCONCAT(',',typeid2,',')LIKE'%,".$typeid.",%'":'';
- }else{//hot排序
- $typesql=$typeid?"WHEREa.arcrank=0anda.typeid=$typeidorCONCAT(',',a.typeid2,',')LIKE'%,".$typeid.",%'and".$orwheres:"WHERE".$orwheres;
- $typesql3=$typeid?"WHEREarcrank=0andtypeid=$typeidorCONCAT(',',typeid2,',')LIKE'%,".$typeid.",%'and".$orwheres:"WHERE".$orwheres;
- }
- //print_r($typesql);exit;
- //这个是用于首页实现瀑布流加载,
- //因为首页加载数据是无需分类的,所以要加以判断,如果无需
- $total_sql="SELECTCOUNT(id)asnumFROM`archives`$typesql3";
- $temp=$dsql->GetOne($total_sql);
- $total=0;//数据总数
- $load_num=0;
- if(is_array($temp)){
- $load_num=round(($temp['num']-$pagesize)/$pagesize);//要加载的次数,因为默认已经加载了
- $total=$temp['num'];
- }
- //print_r($total);exit;
- if($orderby==1){//新
- $sql="SELECTa.*,t.typedir,t.typename,t.isdefault,t.defaultname,t.namerule,
- t.namerule2,t.ispart,t.moresite,t.siteurl,t.sitepath
- FROM`archives`asaJOIN`arctype`AStONa.typeid=t.id$typesqlORDERBYa.idDESCLIMIT$start,$pagesize";
- }else{//热门
- $sql="SELECTa.*,t.typedir,t.typename,t.isdefault,t.defaultname,t.namerule,
- t.namerule2,t.ispart,t.moresite,t.siteurl,t.sitepath
- FROM`archives`asaJOIN`arctype`AStONa.typeid=t.id$typesqlORDERBYa.clickDESCLIMIT$start,$pagesize";
- }
- //echo"$sql";exit;
- $dsql->SetQuery($sql);//
- $dsql->Execute('list');//die(mysql_error());
- $statu=0;//是否有数据,默认没有数据
- $data=array();
- $index=0;
- while($row=$dsql->GetArray("list")){
- $row['info']=$row['info']=$row['infos']=cn_substr($row['description'],250);
- $row['id']=$row['id'];
- $row['typeid2']=get_url_by_typeid2($row['typeid2']);
- $row['filename']=$row['arcurl']=GetFileUrl($row['id'],$row['typeid'],$row['senddate'],$row['title'],$row['ismake'],
- $row['arcrank'],$row['namerule'],$row['typedir'],$row['money'],$row['filename'],$row['moresite'],$row['siteurl'],$row['sitepath']);
- $row['typeurl']=GetTypeUrl($row['typeid'],$row['typedir'],$row['isdefault'],$row['defaultname'],$row['ispart'],$row['namerule2'],$row['moresite'],$row['siteurl'],$row['sitepath']);
- if($row['litpic']=='-'||$row['litpic']==''){
- $row['litpic']=$GLOBALS['cfg_cmspath'].'/images/defaultpic.gif';
- }
- if(!preg_match("#^http:\/\/#i",$row['litpic'])&&$GLOBALS['cfg_multi_site']=='Y'){
- $row['litpic']=$GLOBALS['cfg_mainsite'].$row['litpic'];
- }
- $row['picname']=$row['litpic'];//缩略图
- $row['writer']=$row['writer'];
- $row['click']=$row['click'];
- $row['stime']=GetDateMK($row['pubdate']);
- $row['timeago']=timeago($row['pubdate']);
- $row['typelink']="<arel="nofollow noopener noreferrer" href='".$row['typeurl']."'>".$row['typename']."</a>";//分类链
- $row['fulltitle']=$row['title'];//完整的标题
- $row['shorttitle']=$row['shorttitle'];//副标题
- $row['title']=cn_substr($row['title'],60);//截取后的标题
- $data[$index]=$row;
- $index++;
- }
- if(!empty($data)){
- $statu=1;//有数据
- }
- $result=array('statu'=>$statu,'list'=>$data,'total'=>$total,'load_num'=>$load_num);
- echojson_encode($result);//返回数据
- exit();
- }
以上就是织梦dedecms首页列表页,javascript ajax点击加载更多,瀑布流,首页多栏目切换。人生短短多少十,不要给本人留下了什么遗憾,想笑就笑,想哭就哭,该爱的时候就去爱,无谓压抑自己。更多关于织梦dedecms首页列表页,javascript ajax点击加载更多,瀑布流,首页多栏目切换请关注haodaima.com其它相关文章!