今天逛了一下李学江大神的博客,发现这个功能特别不错,于是转载过来了跟大家分享。 今天终于抽出时间,把代码和教程分享给大家。我所构建的网址导航主要分为以下几个模块:访客网站自动排名第一模块、知名博客模块、人气博客模块、博客大全模块、边栏模块。 下面分模块给大家介绍: 一、访客网站自动排名第一模块 通过调取博客留言者的名字和网址,并去重,按照留言时间顺序排列,最近代链接的留言排在第一位(留言者不填写链接则不显示) 1、把以下代码放入到所用主题的functions。php最后一个aclasstaghrefwiki10484C4。。 最新评论排第一 functionAutofirst(af){ queryafselectcommentauthor,commentauthorurl,commentswherecommentIDin(selectmax(commentID)commentswherecommentapproved’1andcommentauthorurl!anduserid’0GROUPBYcommentauthoremail)ORDERBYcommentdateDESCLIMIT getresults(queryaf); foreach(wallyascommentaf){ tmpy ulclasslistpaddingleft2atargetblankhref。commentauthorurl。。commentauthor。 ; outputy。 } outputy ulclasslistpaddingleft2。outputy。 ; } 其中输出的样式可以自定义,毕竟每一个博客的样式都不一样,这个就靠自己发挥了,只需要在以上代码中的 ulclasslistpaddingleft2中添加一个class属性即可。 2、把以下代码放入需要显示最新访客的地方,如留言板。 !?!? 其中100表示显示100个最新访客,这个数值可以自定义,一定不能为空,要不然会出错,最起码要大于0以上。 二、知名博客模块 显示一定时期内在本站留言比较活跃的用户网站。 !?!? 三、人气博客 显示一定时期内在本站留言数最多的用户网站。 !?!? 四、博客大全 调用你网站的友情链接,由于主题差异,每个网站的调用方法可能不尽相同,如果不懂的话,你可以资讯主题作者。 五、边栏 调用主题边栏,在后台小工具中添加你想要显示的内容。 PS: 1、如果你正在使用知更鸟Begin主题,以上代码全部适用,非知更鸟Begin主题,通过本教程你只能实现最近访客访客自动排名第一功能,如果感兴趣,你也可以参照这篇文章:《WordPress博客如何利用最新评论实现类似导航网站自动排第一功能》。 2、各位在使用的时候,会发现知名博客和人气博客显示的内容与本站有些诧异,如果你希望和本站显示的一样,你可以找到wpcontentthemesbeginincinc。php文件,将约2013至1268行代码替换成以下代码。 读者排行 functiontopcommentauthors(amount98){ prepare( ‘SELECT COUNT(commentauthor)AScommentscount,commentauthor,commentauthorurl,commentauthoremail,MAX(commentdate)aslastcommenteddate FROM‘。comments。’ WHEREcommentauthor!ANDcommenttypeANDcommentapproved1ANDuserid GROUPBYcommentauthor ORDERBYcommentscountDESC,commentauthorASC LIMITd’, amount); getresults(preparedstatement); output‘ ’; foreach(resultsasresult){ output。‘ divclasslx8 ahref‘。url。‘。commentauthor。‘ ’。humantimediff(strtotime(lastcommenteddate))。‘前来过 ’; } output。‘ ’; } functiontopcomments(number98){ countswpcacheget(‘mostactive’); if(falsecounts){ getresults(SELECTCOUNT(commentauthor)AScnt,commentauthor,commentauthorurl,commentauthoremail FROM{prefix}comments WHEREdatesub(NOW(),INTERVAL90DAY) ANDcommentapproved‘1’ ANDcommentauthoremail!‘exampleexample。com’ ANDcommentauthoremail! ANDcommentauthorurl! ANDcommenttype ANDuserid‘0’ GROUPBYcommentauthoremail ORDERBYcntDESC LIMITnumber); } mostactive‘ ’; if(counts){ wpcacheset(‘mostactive’,counts); foreach(countsascount){ mostactive。‘ divclasslx8 ahref‘。url。‘。commentauthor。‘ 留下’。cnt。’个脚印 ’; } mostactive。‘ ’; } } if(zmgetoption(‘metadelete’)){}else{requiregettemplatedirectory()。‘incmetadelete。php’;} requiregettemplatedirectory()。‘incmetaboxes。php’; requiregettemplatedirectory()。‘incshowmeta。php’; 然后使用以下CSS文件。 ?php TemplateName:博客导航 if(!defined(‘ABSPATH’)){} ? !?!? !?csssites。!? 。favoritestop{ margintop:10 } 。breadcrumb, 。yheader{ display: } primary{ float: } sidebar{ float: } 。topcomments{ margin:5px000; } 。topcommentsimg{ float: height: maxwidth:100; width: } 。topcomments。lx8{ float: minheight:1 width:16。6666666666666; padding:2 } 。topauthor{ background: margin:5 padding:0010px0; border:1 } 。topcomment{ color:999; textalign: } 。authorurl{ width:100; padding:5 overflow: textoverflow: whitespace: } 。commentauthors{ padding:010 } 。dhtitle{ background: margin:0010px0; padding:10 border:1 boxshadow:001pxrgba(0,0,0,。04); borderradius:2 } 。dhtitleh3{ fontsize:18 marginleft:10 } 。dhtitle。dhblog{ margin:10px0; } 。dhtitle。dhmore{ position: top:5 right:20 } } article{ background: } siteswidgetoneh3{ fontsize:18 background: width:100; height:30 lineheight:40 padding:020 borderbottom:0 } 。widgetul{ width:100; } 。widgetlinksli{ float: width:20! border:0 } 。widgetlinksa{ border:1 ?phpthetitle(‘ h1’,‘h1’);? functionshowLocale(objD){ varstr,colorhead, varyyobjD。getYear(); if(1900)yyyy1900; varMMobjD。getMonth()1; if(MM10)MM‘0‘MM; varddobjD。getDate(); if(10)dd‘0‘ varhhobjD。getHours(); if(10)hh‘0‘ varmmobjD。getMinutes(); if(10)mm‘0‘ varssobjD。getSeconds(); if(10)ss‘0‘ varwwobjD。getDay(); if(ww0)fontcolorFF0000; if(06)fontcolor373737; if(ww6)fontcolor008000; if(ww0)ww星期日; if(ww1)ww星期一; if(ww2)ww星期二; if(ww3)ww星期三; if(ww4)ww星期四; if(ww5)ww星期五; if(ww6)ww星期六; strcolorheadyy年MM月dd日hh:mm: return(str); } functiontick() { todaynewDate(); document。getElementById(localtime)。innerHTMLshowLocale(today); window。setTimeout(tick(),1000); } tick(); iframeallowtransparencytrueframeborder0width385height75scrollingnosrctianqi。2345。compluginwidgetindex。htm?s1z1t0v0d3bd0q1e1a1c54511w385h96 每当在本站评论时填写网址,贵站将自动排在第一位 ahrefhttps:lixuejiang。 !?!? h3知名博客h3 !?!? h3人气博客h3 !?!? !!! !?!? !!! ?php taxonomy‘favorites’; termsgetterms(taxonomy);foreach(termsascat){ argsarray( ‘showposts’100, ‘metakey’‘sitesorder’, ‘orderby’‘metavalue’, ‘order’‘date’, ‘taxquery’array(array(‘taxonomy’taxonomy,‘terms’catid,‘includechildren’false)) ); querynewWPQuery(args); if(haveposts()){? articleclassdhtitledatawowdelay0。3 h3!??!?h3 divclasssites5 !?haveposts()):thepost();?!? !?ID,‘sitesimglink’,true)){?!? !?phpsitesimglinksitesnofollow(getpostmeta(ID,‘sitesimglink’,true));?!? spanclasssitestitlewowdatawowdelay0 !?!? !?!?!?!? !?!? !?phpsiteslinksitesnofollow(getpostmeta(ID,‘siteslink’,true));?!? spanclasssitestitlewowdatawowdelay0!?!?!?!? !?!? !?!? !?!? !?!? !备用 分类名称 ahref文字替换为网址分类链接地址更多 ulclasssites5listpaddingleft2 ?php argsarray(‘taxquery’array(array(‘taxonomy’‘favorites’,‘field’‘id’,‘terms’explode(‘,’,830))),‘postsperpage’100); queryposts(args);while(haveposts()):thepost(); ? !?ID,‘siteslink’,true)){?!? !?phpsiteslinkgetpostmeta(ID,‘siteslink’,true);?!? ulclasslistpaddingleft2ahref !?!?!?!? !?!? ?phpthetitle(sprintf(‘ ulclasslistpaddingleft2’,escurl(getpermalink())),‘ ’);? !?!? !?!? !?!? divclasswowdatawowdelay0。5 !?phpif:!? h3添加小工具h3 !?widgets。为网址侧边栏添加小工具!? !?!? !?!? 注意,本代码仍然只适用于知更鸟Begin主题。 本文所有权归李学江博客所有,转载请注明来源:https:lixuejiang。comwordpress2496。htm