php生成站点地图,WordPress免插件生成完整站点地图(sitemap.xml)的php代码

require(‘./wp-blog-header.php’);

header("Content-type: text/xml");

header(‘HTTP/1.1 200 OK’);

$posts_to_show = 1000;

echo ‘<?xml version="1.0" encoding="UTF-8"?>’;

echo ‘’

?>

Diy By 张戈博客(http://zhangge.net)–>

daily

1.0

/* 文章页面 */

$myposts = get_posts( "numberposts=" . $posts_to_show );

foreach( $myposts as $post ) { ?>

monthly

0.6

/* 单页面 */

$mypages = get_pages();

if(count($mypages) > 0) {

foreach($mypages as $page) { ?>

<?php echo get_page_link($page->ID); ?>

<?php echo str_replace(" ","T",get_page($page->ID)->post_modified); ?>+00:00

weekly

0.6

/* 博客分类 */

$terms = get_terms(‘category’, ‘orderby=name&hide_empty=0’ );

$count = count($terms);

if($count > 0){

foreach ($terms as $term) { ?>

<?php echo get_term_link($term, $term->slug); ?>

weekly

0.8

/* 标签(可选) */

$tags = get_terms("post_tag");

foreach ( $tags as $key => $tag ) {

$link = get_term_link( intval($tag->term_id), "post_tag" );

if ( is_wp_error( $link ) )

return false;

$tags[ $key ]->link = $link;

?>

monthly

0.4

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值