WordPress免插件实现HTML网站地图

站点建设评论10K1字数 2940阅读9分48秒阅读模式

WordPress有很多生成Sitemap的插件,以前都是用柳城的(Baidu Sitemap Generator ),本着强迫症的原则,在网上搜了下纯代码版的。下面记录下本站实现HTML网站地图的过程。

建议配合 WordPress免插件实现XML网站地图,效果更好。文章源自亦枫博客-https://yflad.cn/527.html

 文章源自亦枫博客-https://yflad.cn/527.html

1、新建一个sitemap.php至主题目录下,复制下面代码粘贴:文章源自亦枫博客-https://yflad.cn/527.html

点击

展开收缩
文章源自亦枫博客-https://yflad.cn/527.html
  1. <?php
  2. /*
  3.  Template Name: Sitemap
  4. */
  5. ?>
  6. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  7. <html xmlns="http://www.w3.org/1999/xhtml">
  8. <head profile="http://gmpg.org/xfn/11">
  9. <meta http-equiv="Content-Type" content="text/html; charset=<?php bloginfo( 'charset' ); ?>" />
  10. <title>站点地图 | <?php bloginfo('name'); ?></title>
  11. <meta name="keywords" content="站点地图,<?php bloginfo('name'); ?>" />
  12. <meta name="copyright" content="<?php bloginfo('name'); ?>" />
  13. <link rel="canonical" href="<?php echo get_permalink(); ?>" />
  14. <style type="text/css">
  15.     body {font-family: Microsoft Yahei,Verdana;font-size:13px;margin:0 auto;color: #000000;background: #ffffff;width: 990px;margin: 0 auto}
  16.     a:link,a:visited {color:#000;text-decoration:none;}
  17.     a:hover {color:#08d;text-decoration:none;}
  18.     h1,h2,h3,h4,h5,h6 {font-weight:normal;}
  19.     img {border:0;}
  20.     li {margin-top: 8px;}
  21.     .page {padding: 4px; border-top: 1px #EEEEEE solid}
  22.     .author {background-color:#EEEEFF; padding: 6px; border-top: 1px #ddddee solid}
  23.     #nav, #content, #footer {padding: 8px; border: 1px solid #EEEEEE; clear: both; width: 95%; margin: auto; margin-top: 10px;}
  24. </style>
  25. </head>
  26. <body vlink="#333333" link="#333333">
  27. <h2 style="text-align: center; margin-top: 20px"><?php bloginfo('name'); ?>'s SiteMap </h2>
  28. <center></center>
  29. <div id="nav"><a href="<?php bloginfo('url'); ?>/"><strong><?php bloginfo('name'); ?></strong></a> &raquo; <a href="<?php echo get_permalink(); ?>">站点地图</a></div>
  30. <div id="content">
  31. <h3>最新文章</h3>
  32. <ul>
  33. <?php
  34. $previous_year = $year = 0;
  35. $previous_month = $month = 0;
  36. $ul_open = false;
  37. $myposts = get_posts('numberposts=-1&orderby=post_date&order=DESC');
  38. foreach($myposts as $post) :
  39. ?>
  40. <li><a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>" target="_blank"><?php the_title(); ?></a></li>
  41. <?php endforeach; ?>
  42. </ul>
  43. </div>
  44. <div id="content">
  45. <li class="categories">分类目录<ul>
  46. <?php wp_list_categories('title_li='); ?>
  47. </ul></li>
  48. </div>
  49. <div id="content">
  50. <li class="categories">单页面</li>
  51. <?php wp_page_menu( $args ); ?>
  52. </div>
  53. <div id="footer">查看博客首页: <strong><a href="<?php bloginfo('url'); ?>/"><?php bloginfo('name'); ?></a></strong></div><br />
  54. <center>
  55. <div style="text-algin: center; font-size: 11px"><strong><a href="https://yflad.cn/sitemap.xml" target="_blank">站点地图</a></strong> Latest Update: <?php $last = $wpdb->get_results("SELECT MAX(post_modified) AS MAX_m FROM $wpdb->posts WHERE (post_type = 'post' OR post_type = 'page') AND (post_status = 'publish' OR post_status = 'private')");$last = date('Y-m-d G:i:s', strtotime($last[0]->MAX_m));echo $last; ?><br /><br /></div>
  56. </center>
  57. </body>
  58. </html>

 文章源自亦枫博客-https://yflad.cn/527.html

文章源自亦枫博客-https://yflad.cn/527.html

 文章源自亦枫博客-https://yflad.cn/527.html

2、然后“新建页面”(如下图所示)。修改固定链接样式:WordPress免插件实现HTML网站地图文章源自亦枫博客-https://yflad.cn/527.html

 文章源自亦枫博客-https://yflad.cn/527.html

3、然后将页面的链接加入到自己的想要的地方,可以自己任何地方调用。比如footer.php里。(因为各主题不一,贴下自己的吧)WordPress免插件实现HTML网站地图文章源自亦枫博客-https://yflad.cn/527.html

 文章源自亦枫博客-https://yflad.cn/527.html

4、本站演示HTML版站点地图:yflad.cn/sitemap文章源自亦枫博客-https://yflad.cn/527.html 文章源自亦枫博客-https://yflad.cn/527.html

继续阅读
扫扫关注公众号
weinxin
我的微信
扫扫体验小程序
weinxin
我的公众号
亦枫
  • 本文由 发表于 2017年6月5日 05:00:31
评论  0  访客  0
匿名

发表评论

匿名网友 填写信息

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定