个人博客WordPress内容管理系统站点获取所有链接的PHP代码
有时需要提取网站的所有链接。使用软件获取网站链接容易出现大量重复链接。给大家分享一段php代码,一键获取WordPress站点的所有链接,包括页面单页、文章页、分类页。 ,tag标签页,简单实用。
<?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"; } ?>
可以将以上代码保存为后缀.PHP,上传至网站根目录,在浏览器中输入相应的地址就获取所有站点的链接了,
💯扫描二维码推送至手机访问。
💢版权声明:本文由小龟网发布,如需转载请注明出处。
🤗作品 采用知识共享署名-非商业性使用-相同方式共享 4.0 国际许可协议 进行许可