华纳云香港服务器

WordPress博客如何构造一个智能排名网址导航站

WordPress主题推荐

网络上很多导航站的源码都是 PHP 语言或其他系统,但是 WordPress 方面的导航站倒是很少,今天我就跟大家分享一下 WordPress 博客如何构造一个智能排名网址导航站。我所构建的网址导航主要分为以下几个模块:访客网站自动排名第一模块、知名博客模块、人气博客模块、博客大全模块、边栏模块。具体效果请点此查看

WordPress博客如何构造一个智能排名网址导航站-第1张-boke112百科(boke112.com)

一、访客网站自动排名第一模块

通过调取博客留言者的名字和网址,并去重,按照留言时间顺序排列,显示最近带链接的留言排在第一位(留言者不填写链接则不显示),具体效果如下:

WordPress博客如何构造一个智能排名网址导航站-第2张-boke112百科(boke112.com)

1、把以下代码放入到所用主题的 functions.php 最后一个%>。

  1. //最新评论排第一
  2. function Autofirst($af){
  3.     global $wpdb;
  4.     $queryaf=“select comment_author, comment_author_url, comment_date from $wpdb->comments where comment_ID in (select max(comment_ID) from $wpdb->comments where comment_approved=’1′ and comment_author_url !=” and user_id=’0′  GROUP BY comment_author_email)  ORDER BY comment_date DESC LIMIT $af”;
  5.     $wally = $wpdb->get_results($queryaf);
  6.     foreach ($wally as $commentaf){
  7.         $tmpy“<li><a target=\”_blank\” href=\””.$commentaf->comment_author_url.“\”>”.$commentaf->comment_author.“</a></li>”;
  8.         $outputy .= $tmpy;
  9.     }
  10.     $outputy = “<ul>”.$outputy.“</ul>”;
  11.     echo $outputy ;
  12. }

其中输出的样式可以自定义,毕竟每一个博客的样式都不一样,这个就靠自己发挥了,只需要在以上代码中的<ul>中添加一个 class 属性即可。

2、把以下代码放入需要显示最新访客的地方。

  1. <?php Autofirst(100);?>

其中 100 表示显示 100 个最新访客,这个数值可以自定义,一定不能为空,要不然会出错,最起码要大于 0 以上。

二、知名博客模块

这个模块主要是显示一定时期内在本站留言比较活跃的用户网站。

WordPress博客如何构造一个智能排名网址导航站-第3张-boke112百科(boke112.com)

  1. <?php top_comment_authors(24); ?>

注意:本模块仅适用于知更鸟Begin 主题,括号里面的数字为显示数量,你可以按需修改。

PS:boke112 认为这个这个模块既然叫做知名博客模块,不如做成展示名气比较大的独立博客,这样方面用户知道哪些是知名博客,也方面用户直接访问这些知名博客。

三、人气博客模块

这个模块主要是显示一定时期内在本站留言数最多的用户网站。

WordPress博客如何构造一个智能排名网址导航站-第4张-boke112百科(boke112.com)

  1. <?php top_comments(24); ?>

注意:本模块仅适用于知更鸟 Begin 主题,括号里面的数字为显示数量,你可以按需修改。

四、博客大全模块

这个模块调用网站的友情链接,由于主题差异,每个网站的调用方法可能不尽相同,如果不懂的话,你可以资讯主题作者。

WordPress博客如何构造一个智能排名网址导航站-第5张-boke112百科(boke112.com)

五、边栏模块

调用主题侧边栏,在后台小工具中添加你想要显示的内容。

温馨提示:

1、如果你正在使用知更鸟Begin 主题,以上代码全部适用,非知更鸟 Begin 主题,通过本教程你只能实现最近访客访客自动排名第一功能,如果感兴趣,你也可以参照这篇文章:《WordPress 博客导航实现最新评论自动排第一功能》。

2、各位在使用的时候,会发现知名博客和人气博客显示的内容与本站有些诧异,如果你希望和本站显示的一样,你可以找到/wp-content/themes/begin/inc/inc.php 文件,将约 2013 至 1268 行代码替换成以下代码。

  1. // 读者排行
  2. function top_comment_authors($amount = 98) {
  3.     global $wpdb;
  4.         $prepared_statement = $wpdb->prepare(
  5.         ‘SELECT
  6.         COUNT(comment_author) AS comments_count, comment_author, comment_author_url, comment_author_email, MAX( comment_date ) as last_commented_date
  7.         FROM ‘.$wpdb->comments.’
  8.         WHERE comment_author != “” AND comment_type = “” AND comment_approved = 1  AND user_id = “”
  9.         GROUP BY comment_author
  10.         ORDER BY comments_count DESC, comment_author ASC
  11.         LIMIT %d’,
  12.         $amount);
  13.     $results = $wpdb->get_results($prepared_statement);
  14.     $output = ‘<div class=“top-comments”>’;
  15.     foreach($results as $result) {
  16.         $c_url = $result->comment_author_url;
  17.         $output .= ‘
  18.         <div class=“lx8”>
  19.             <div class=“top-author”>
  20.                 <div class=“top-comment”><a href=“‘ . get_template_directory_uri().”/inc/go.php?url=“. $c_url . ‘” target=“_blank” rel=“external nofollow”><div class=“author-url”><strong> ‘ . $result->comment_author . ‘</div></strong></a></div>
  21.                 <div class=“top-comment”>’ . human_time_diff(strtotime($result->last_commented_date)) . ‘前来过</div>
  22.             </div>
  23.         </div>’;
  24.     }
  25.     $output .= ‘<div class=“clear”></div></div>’;
  26.     echo $output;
  27. }
  28. function top_comments($number = 98) {
  29.     global $wpdb;
  30.     $counts = wp_cache_get( ‘mostactive’ );
  31.     if ( false === $counts ) {
  32.         $counts = $wpdb->get_results(“SELECT COUNT(comment_author) AS cnt, comment_author, comment_author_url, comment_author_email
  33.         FROM {$wpdb->prefix}comments
  34.         WHERE comment_date > date_sub( NOW(), INTERVAL 90 DAY )
  35.         AND comment_approved = ‘1’
  36.         AND comment_author_email != ‘[email protected]
  37.         AND comment_author_email != ”
  38.         AND comment_author_url != ”
  39.         AND comment_type = ”
  40.         AND user_id = ‘0’
  41.         GROUP BY comment_author_email
  42.         ORDER BY cnt DESC
  43.         LIMIT $number”);
  44.     }
  45.     $mostactive =  ‘<div class=“top-comments”>’;
  46.     if ( $counts ) {
  47.         wp_cache_set( ‘mostactive’, $counts );
  48.         foreach ($counts as $count) {
  49.             $c_url = $count->comment_author_url;
  50.             $mostactive .= ‘
  51.             <div class=“lx8”>
  52.                 <div class=“top-author”>
  53.                     <div class=“top-comment”><a href=“‘ . get_template_directory_uri().”/inc/go.php?url=“. $c_url . ‘” target=“_blank” rel=“external nofollow”><div class=“author-url”><strong> ‘ . $count->comment_author . ‘</div></strong></a></div>
  54.                     <div class=“top-comment”>留下’.$count->cnt.’个脚印</div>
  55.                 </div>
  56.             </div>’;
  57.         }
  58.         $mostactive .= ‘<div class=“clear”></div></div>’;
  59.         echo $mostactive;
  60.     }
  61. }
  62. if (zm_get_option(‘meta_delete’)) {} else {require get_template_directory() . ‘/inc/meta-delete.php’;}
  63. require get_template_directory() . ‘/inc/meta-boxes.php’;
  64. require get_template_directory() . ‘/inc/show-meta.php’;

然后使用以下 CSS 代码文件。

  1. .favorites-top{
  2.     margin-top:10px;
  3. }
  4. .breadcrumb,
  5. .yheader{
  6.     display:none;
  7. }
  8. #primary {
  9.     floatleft;
  10. }
  11. #sidebar {
  12.     float: rightright;
  13. }
  14. .top-comments {
  15.     margin: –5px 0 0 0;
  16. }
  17. .top-comments img {
  18.     floatleft;
  19.     heightauto;
  20.     max-width: 100%;
  21.     widthauto;
  22. }
  23. .top-comments .lx8 {
  24.     floatleft;
  25.     min-height1px;
  26.     width: 16.6666666666666%;
  27.     padding2px;
  28. }
  29. .top-author {
  30.     background#fff;
  31.     margin5px;
  32.     padding: 0 0 10px 0;
  33.     border1px solid #ddd;
  34. }
  35. .top-comment {
  36.     color#999;
  37.     text-aligncenter;
  38. }
  39. .author-url {
  40.     width: 100%;
  41.     padding5px;
  42.     overflowhidden;
  43.     text-overflow: ellipsis;
  44.     whitewhite-space: nowrap;
  45. }
  46. .comment-authors {
  47.     padding: 0 10px;
  48. }
  49. .dh_title{
  50.     background#fff;
  51.     margin: 0 0 10px 0;
  52.     padding10px;
  53.     border1px solid #ddd;
  54.     box-shadow: 0 0 1px rgba(0,0,0,.04);
  55.     border-radius: 2px;
  56. }
  57. .dh_title h3{
  58.     font-size18px;
  59.     margin-left:10px;
  60. }
  61. .dh_title .dh_blog{
  62.     margin:10px 0;
  63. }
  64. .dh_title .dh_more{
  65.     positionabsolute;
  66.     top5px;
  67.     rightright: 20px;
  68. }
  69. }
  70. article{
  71.     background:#fff;
  72. }
  73. #sites-widget-one h3 {
  74.     font-size18px;
  75.     background#fff;
  76.     width: 100%;
  77.     height30px;
  78.     line-height40px;
  79.     padding: 0 20px;
  80.     border-bottom0px solid #ddd;
  81. }
  82. .widget ul{
  83.     width: 100%;
  84. }
  85. .widget_links li{
  86.     floatleft;
  87.     width: 20% !important;
  88.     border:0px;
  89. }
  90. .widget_links a{
  91.     border1px solid #fff;

懒人福利

如果你和我一样,比较懒惰,你可以新建一个 PHP 页面文件,加入以下代码,将文件上传至/wp-content/themes/begin/pages/,然后在后台,新建页面,模板选择博客导航即可。

注意,本代码仍然只适用于知更鸟 Begin 主题。

赞 (0) 打赏
版权声明:本文为转载文章,来源于 Jane博客 ,版权归原作者所有!发布此文是出于传递更多信息之目的,若有来源标注错误或侵犯了您的合法权益,请联系我们,确认后马上更正或删除,谢谢!
wu