WordPress免插件实现HTML网站地图

WordPress免插件实现HTML网站地图。许多WordPress主题都是不带有这个网站地图页面的,也就需要我们自己来实现了。这里分享的一个代码页面是来自云落GIT主题的网站地图。放来这里,方便下自己也方便下他人。本站使用的是begin主题,所以这里也就已begin主题为例。在新建一个PHP文件页面template-...

WordPress免插件实现HTML网站地图。许多WordPress主题都是不带有这个网站地图页面的,也就需要我们自己来实现了。这里分享的一个代码页面是来自云落GIT主题的网站地图。放来这里,方便下自己也方便下他人。

本站使用的是begin主题,所以这里也就已begin主题为例。在新建一个PHP文件页面template-sitemap.php,在里面加上以下代码,再放入主题下的页面文件夹中。

<?php/* Template Name: 站点地图*/?><!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%20echo%20get_permalink();%20?>" /><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%20echo%20esc_url(%20home_url()%20);%20?>/"><strong><?php bloginfo('name'); ?></strong></a> &raquo; <a href="<?php%20echo%20get_permalink();%20?>">站点地图</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%20the_permalink();%20?>" 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%20echo%20esc_url(%20home_url()%20);%20?>/"><?php bloginfo('name'); ?></a></strong></div><br /><center><div style="text-algin: center; font-size: 11px">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>

然后再在后台新建一个页面,模板选择 站点地图 就可以了。会显示所有文章、页面和分类。

声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。

给TA打赏
共{{data.count}}人
人已打赏
wordpress教程

WordPress网站主机遭受攻击关停怎么办?

2023-2-16 15:53:01

wordpress教程

WordPress网站的中文标签想要实现伪静态该如何解决呢?

2023-2-16 15:53:03

!
你也想出现在这里?立即 联系我们吧!
信息
0 条回复 A文章作者 M管理员
    暂无讨论,说说你的看法吧
个人中心
购物车
优惠劵
今日签到
搜索