wordpress获取网站全部链接
in 各种技术 with 0 comment

wordpress获取网站全部链接

in 各种技术 with 0 comment

其实好多地方都会用到这个全站链接,比如说向百度推送网站文章的时候,之前从他们那修改过,这里就直接拿来用了

完整代码

<?php  
require('./wp-blog-header.php');  
header("Content-type: text/txt");  
header('HTTP/1.1 200 OK');  
$posts_to_show = 1000; // 获取文章数量  
?>  
<?php echo 'http://'.$_SERVER['HTTP_HOST']; ?><?php echo "\n"; ?>  
<?php  
/* 文章页面 */  
header("Content-type: text/txt");  
$myposts = get_posts( "numberposts=" . $posts_to_show );  
foreach( $myposts as $post ) {  
    the_permalink();   
    echo "\n";   
}  
?>  
<?php  
/* 单页面 */   
$mypages = get_pages();  
if(count($mypages) > 0) {  
    foreach($mypages as $page) {  
    echo get_page_link($page->ID);  
    echo "\n";  
    }  
}  
?>  
<?php  
/* 博客分类 */   
$terms = get_terms('category', 'orderby=name&hide_empty=0' );  
$count = count($terms);  
if($count > 0){  
foreach ($terms as $term) {  
    echo get_term_link($term, $term->slug);  
    echo "\n";  
    }  
}   
?>  
<?php  
 /* 标签(可选) */  
    $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;  
               }  
                  echo $link;  
                  echo "\n";  
    }            
?>

复制这段代码,然后保存为url.php,上传至网站根目录,然后访问域名/url.php就可以了!(文件名字可以自定义)

演示:https://www.79ui.com/sitemap.php

UC截图20180526111526.png

使用范围:网站链接提交,百度站内搜索链接提交

懒人包

url.zip

解压后即可得到url.php,上传至网站根目录

版权说明

本文转载自:https://www.5v13.com/wordpress/4194.html

Responses