WordPress使用代码为博客创建一个站点地图页面

摘要:都知道wordpress是不自带站点地图,我们可以通过相应的插件来实现, 但我们知道wordpre…

WordPress使用代码为博客创建一个站点地图页面
使用代码为博客创建一个站点地图页面,也有插件啦,不过插件多了也不好啦,所以这个就教大家一下咯

新创建一个PHP文件,名称:sitemap.php
将以下代码放入sitemap.php文件中
然后上传至自己正在使用主题的目录
到后台页面-新建页面,选择sitemap页面模板

配图教程

WordPress使用代码为博客创建一个站点地图页面

代码

 

<?php
/*
Template Name: Sitemap
*/
?>
<!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 bloginfo( 'charset' ); ?>" />
<title>站点地图 - <?php bloginfo('name'); ?></title>
<meta name="keywords" content="站点地图,<?php bloginfo('name'); ?>" />
<meta name="copyright" content="<?php bloginfo('name'); ?>" />
<link rel="canonical" href="<?php echo get_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 bloginfo('name'); ?>'s SiteMap </h2>
<center></center>
<div id="nav"><a href="<?php bloginfo('url'); ?>/"><strong><?php bloginfo('name'); ?></strong></a> » <a href="<?php echo get_permalink(); ?>">站点地图</a></div>
<div id="content">
<h3>最新文章</h3>
<ul>
<?php
$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="<?php the_permalink(); ?>" title="<?php the_title(); ?>" target="_blank"><?php the_title(); ?></a></li>
<?php endforeach; ?>
</ul>
</div>
<div id="content">
<li class="categories">分类目录<ul>
<?php wp_list_categories('title_li='); ?>
</ul></li>
</div>
<div id="content">
<li class="categories">单页面</li>
<?php wp_page_menu( $args ); ?>
</div>
<div id="footer">查看博客首页: <strong><a href="<?php bloginfo('url'); ?>/"><?php bloginfo('name'); ?></a></strong></div><br />
<center>
<div style="text-algin: center; font-size: 11px"><strong><a rel="nofollow" target="_blank" class="a-one" href="https://www.ly522.com/go?url=aHR0cHM6Ly93d3cuc2hhcmVwcHAuc2l0ZS9zaXRlbWFwLnhtbA==" /*这里是自己站点的xml版本的站点地图地址*/target="_blank">Baidu-SiteMap</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>
</center>
</body>
</html>

效果演示:https://www.ly522.com/sitemap.html

效果图

WordPress使用代码为博客创建一个站点地图页面

 

原文地址:https://www.ly522.com/1831.html

WordPress使用代码为博客创建一个站点地图页面

给TA打赏
共{{data.count}}人
人已打赏
资源下载说明

请使用百度网盘下载资源,不要在线解压!

1、本网站名称:美萌资源网
2、本站网址:www.mmupup.com
3、关于下载后怎么观看的问题,请查看网站首页的:关于充值、会员、资源、解压等部分说明【必看】
4、本站大部分资源解压密码均为: clubmeitu.com或者7mct.cn
5、本站资源大多存储在网盘,如发现链接失效查看文章联系作者进行补档或留言


本站说明

本站主要为大家提供时尚的Cospaly小姐姐美图,天天更新Cos套图,更多福利,小姐姐,写真,宅男精品,和cosplay等精彩内容,尽情关注美萌资源网永久发布页:http://www.cosclub.top/,我们只是大自然的搬运工,我们不生成小姐姐,我们只搬运小姐姐。如有侵权请联系删除,谢谢!!Email:1638590630@qq.com

0 条回复 A文章作者 M管理员
    暂无讨论,说说你的看法吧
个人中心
购物车
优惠劵
今日签到
有新私信 私信列表
搜索