【江苏省公安厅】高考在即,各位考生和家长务必提高警惕!凡是声称可以提前获取考题答案的、有“内部渠道”提前录取的、提前缴纳学费、保证金的,或是要求点击不明链接以获取上述服务的,都是诈骗。

Typecho文档-为站点生成网站地图

发布于: 2025-05-11 所属类目: typecho

文档说明:
网站地图(Sitemap)是优化搜索引擎抓取和提升网站收录的重要工具。
具体来说,它能够提升搜索引擎对网站的抓取效率,帮助搜索引擎了解网站的结构,抓取更深层次的页面,从而增加索引概率,提高被收录的可能,优化SEO效果。
今天,小刘就给大家分享如何使用纯代码来为网站添加站点地图。

效果预览:
点我查看

涉及文件:

usr/themes/当前正在使用的模版/

使用说明:
1.访问usr/themes/当前正在使用的模版/
2.在该目录下新建一个PHP文件,文件名随意
3.在新建的PHP文件中粘贴如下代码:

<?php
/**
*HTML版网站地图Sitemap
*
* @package custom
*/
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head profile="http://gmpg.org/xfn/11">
  <meta http-equiv="Content-Type" content="text/html; charset=<?php $this->options->charset(); ?>" />
  <title>站点地图 - <?php $this->options->title() ?></title>
  <meta name="keywords" content="站点地图,<?php $this->options->title() ?>" />
  <meta name="copyright" content="<?php $this->options->title() ?>" />
  <link rel="canonical" href="<?php $this->permalink() ?>" />
  <style type="text/css">
body {font-family: Microsoft Yahei,Verdana;font-size:13px;margin:0 auto;color: #000000;background: #ffffff;width: 990px;margin: 0 auto}
a:link,a:visited {color:#000;text-decoration:none;}
a:hover {color:#08d;text-decoration:none;}
h1,h2,h3,h4,h5,h6 {font-weight:normal;}
img {border:0;}
li {margin-top: 8px;}
.page {padding: 4px; border-top: 1px #EEEEEE solid}
.author {background-color:#EEEEFF; padding: 6px; border-top: 1px #ddddee solid}
#nav, #content, #footer {padding: 8px; border: 1px solid #EEEEEE; clear: both; width: 95%; margin: auto; margin-top: 10px;}
  </style>
</head>
<body vlink="#333333" link="#333333">
  <h2 style="text-align: center; margin-top: 20px"><?php $this->options->title() ?>'s SiteMap </h2>
  <center></center>
  <div id="nav"><a href="<?php $this->options ->siteUrl(); ?>"><strong><?php $this->options->title() ?></strong></a> » <a href="<?php $this->permalink() ?>">站点地图</a></div>
  <div id="content">
<h3>最新文章</h3>
<ul>
  <?php
  $stat = Typecho_Widget::widget('Widget_Stat');
  $this->widget('Widget_Contents_Post_Recent', 'pageSize='.$stat->publishedPostsNum)->to($archives);
  $year=0; $mon=0; $i=0; $j=0;
  while($archives->next()){
      $year_tmp = date('Y',$archives->created);
      $mon_tmp = date('m',$archives->created);
      $y=$year; $m=$mon;
      if ($year > $year_tmp || $mon > $mon_tmp) {
          $output .= '</ul>';
      }
      $output .= '<li><a href="'.$archives->permalink .'">'. $archives->title .'</a></li>';
  }
  $output .= '</ul>';
  echo $output;
  ?>
</ul>
  </div>
  <div id="content">
<li class="categories">分类目录
  <ul><?php $this->widget('Widget_Metas_Category_List')
           ->parse('<li><a href="{permalink}">{name}</a> ({count})</li>'); ?>
  </ul>
</li>
  </div>
  <div id="content">
<li class="categories">独立页面</li>
<ul class="clearfix" id="nav_menu">
  <li><a href="<?php $this->options->siteUrl(); ?>">首页</a></li>
  <?php $this->widget('Widget_Contents_Page_List')
             ->parse('<li><a href="{permalink}">{title}</a></li>'); ?>
</ul>
  </div>
  <div id="footer">查看博客首页: <strong><a href="<?php $this->options ->siteUrl(); ?>"><?php $this->options->title() ?></a></strong></div><br />
  <center>
<div style="text-algin: center; font-size: 11px"><br /> © <?php echo date('Y'); ?> <strong><a href="<?php $this->options ->siteUrl(); ?>" target="_blank"><?php $this->options->title() ?></a></strong> 版权所有<br /><br /><br />
</div>
  </center>
</body>
</html>

4.进入Typecho后台→创建页面,右侧自定义模版选择“HTML版网站地图Sitemap”,点击发布页面。

微信扫码分享

请使用微信扫描二维码分享

网站已运行 47 天 | 共有文章 43 篇