[WordPress]纯代码获取WordPress站点全部链接 可用于收录提交-第1张

给大家分享一段能够直接获取WordPress站点所有文章链接。其实建站好多地方都会用到这个全站链接,比如说向百度推送网站文章的时候等等。

复制以下代码,然后保存为rul.php,上传至网站根目录,然后访问域名/rul.php就可以了!

<?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"; }
?>

演示预览:

例如我的:https://www.liitk.com/url.php

[WordPress]纯代码获取WordPress站点全部链接 可用于收录提交-第2张

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

声明:本站文章原创有部分资源来源于网络,如无特殊说明或标注。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系 admin@liitk.com 进行删除处理!。