欢迎您光临自学哈网,只为分享网络知识教程,供大家学习参考!

「自学哈网」WordPress免插件实现HTML网站地图

作者 : 自学哈 本文共2670个字,预计阅读时间需要7分钟 2022-11-26 共109人阅读
也想出现在这里? 联系我们

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 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 echo esc_url( home_url() ); ?>/\"><strong><?php bloginfo(\'name\'); ?></strong></a> &raquo; <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 echo esc_url( home_url() ); ?>/\"><?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>

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

本站声明:
本站所有资源来源于网络,分享目的仅供大家学习和交流!如若本站内容侵犯了原著者的合法权益,可联系邮箱976157886@qq.com进行删除。
自学哈专注于免费提供最新的分享知识、网络教程、网络技术的资源分享平台,好资源不私藏,大家一起分享!

自学哈网 » 「自学哈网」WordPress免插件实现HTML网站地图
也想出现在这里? 联系我们
© 2022 Theme by - 自学哈网 & WordPress Theme. All rights reserved 浙ICP备2022016594号