WordPress的网站地图(sitemap)代码文件使用方法:
一、在主题的根目录新建一个名为sitemap.php的文件,将下放的代码放入文件中保存:
<?php
/*
Template Name: 网站地图
*/
$text_logo = b2_get_option('normal_main', 'text_logo');
$img_logo = b2_get_option('normal_main', 'img_logo');
?>
<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;
}
.login-logo {
text-align: center;
}
</style>
</head>
<body vlink="#333333" link="#333333">
<h1 class="sc-fznWOq kxKJMB sc-fzqBkg hNumnz">
<font>
<div class="login-logo" onclick="location.href = '<?php bloginfo('url') ?>'"><?php echo ($img_logo ? '<img src="' . $img_logo . '" />' : $text_logo); ?></div>
</font>
</h1>
<center>
</center>
<div id="nav"><a href="<?php echo esc_url(home_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&showposts=100&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="content">
<h1><?php _e('所有话题', 'jinsom'); ?></h1>
<ul>
<?php wp_tag_cloud('number=2000'); ?>
</ul>
</div>
<div id="content">
<h1><?php echo '最新注册用户'; ?></h1>
<ul>
<?php
$user_query = new WP_User_Query(array(
'orderby' => 'registered',
'order' => 'DESC',
'count_total' => false,
'number' => 100
));
if (!empty($user_query->results)) {
foreach ($user_query->results as $user) {
$user_data = get_userdata($user->ID);
echo '<li><a href="' . get_author_posts_url($user->ID) . '" title="' . $user_data->display_name . '" target="_blank">' . $user_data->display_name . '</a></li>';
}
}
?>
<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>
二、后台编辑新建页面
1、以上完成之后,打开wordpress后台,页面->新建页面->模板选择->网站地图,保存页面。
2、打开(查看)这个页面,完成。
一、本站上的部份代码及教程来源于互联网,仅供网友学习交流。如有侵权,无意侵害您的权益,请发送邮件至xutian#ahap.cn或点击右侧 联系我们,我们将尽快处理。
二、请勿将购买的资源教程转载或分享与他人!
二、请勿将购买的资源教程转载或分享与他人!