国内外主机
测评及优惠码

如何为WordPress创建站点地图?

如何为WordPress创建站点地图?

网站地图对于SEO来说,有一定的好处,如何为WordPress创建站点地图?一般WordPress默认是没有站点地图功能的,还要去装插件来实现,为了少装点插件,我觉得不如靠写点代码来实现:

创建一个php文件名称为:

page-sitemap.php

然后里面代码放上:

/*  Template Name: 站点地图  */  ?>  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=" />      <title>站点地图 -  bloginfo('name'); ?>title>      <meta name="keywords" content="站点地图," />      <meta name="copyright" content="" />      <link rel="canonical" href="" />      <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"> bloginfo('name'); ?>'s SiteMap h2>      <center>center>      <div id="nav">          <a href="/"><strong> bloginfo('name'); ?>strong>a> » <a href="">站点地图a>      div>      <div id="content">          <h3>最新文章h3>          <ul>                          $previous_year = $year = 0;              $previous_month = $month = 0;              $ul_open = false;              $myposts = get_posts('numberposts=-1&orderby=post_date&order=DESC');              foreach ($myposts as $post) :              ?>              <li><a href="                ?>" title="                ?>" target="_blank"> the_title();                  ?>a>li>               endforeach;              ?>          ul>      div>      <div id="content">          <li class="categories">分类目录<ul>               wp_list_categories('title_li='); ?>          ul>          li>      div>      <div id="content">          <li class="categories">单页面li>           wp_page_menu($args); ?>      div>      <div id="footer">          查看博客首页: <strong><a href="/"> bloginfo('name'); ?>a>strong>      div>      <br />      <center>          <div style="text-algin: center; font-size: 11px">Latest Update:  $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>      center>  body>  html>

然后打开你的WordPress后台-页面-新建页面-模板选择-站点地图即可。

赞(0)
版权声明:本文采用知识共享 署名4.0国际许可协议 [BY-NC-SA] 进行授权
文章名称:《如何为WordPress创建站点地图?》
文章链接:https://www.ibytx.com/2531.html
本站资源仅供个人学习交流,请于下载后24小时内删除,不允许用于商业用途,否则法律问题自行承担。

登录

找回密码

注册