WordPress生成sitemap

在根目录新建文件sitemap.php,将以下的代码复制进去

 'uncategorized'"; 
  $sqltag="select taxonomy,slug from wp_term_taxonomy JOIN wp_terms on wp_terms.term_id=wp_term_taxonomy.term_id where taxonomy='post_tag'"; 
  $myrowscat = $wpdb->get_results($sqlcat);
  $myrowstag = $wpdb->get_results($sqltag);
  $str = '
';
	$str.="
	
	".$qianzui."
	".date('Y-m-d')."
	weekly
	1.0
	
	";
  foreach ($myrowscat as $b) { 
  	$str.="\r\n";
	$str.="".$qianzui."/category/".$b->slug."\r\n";
	$str.="".date("Y-m-d")."\r\n";
	$str.="weekly\r\n";
	$str.="0.9\r\n";
	$str.="\r\n";
  }
  foreach ($myrowstag as $b) { 
  	$str.="\r\n";
	$str.="".$qianzui."/tag/".$b->slug."\r\n";
	$str.="".date("Y-m-d")."\r\n";
	$str.="weekly\r\n";
	$str.="0.9\r\n";
	$str.="\r\n";
  }
$myposts = get_posts();
foreach( $myposts as $post ) {
	$str.="\r\n";
	$str.="".urldecode(get_permalink())."\r\n";
	$str.="".date("Y-m-d")."\r\n";
	$str.="weekly\r\n";
	$str.="0.8\r\n";
	$str.="\r\n";
 } 
$str.="";
file_put_contents('./sitemap.xml',$str);
echo 'update sitemap.xml success  查看';
?>

运行http://yourdomain.com/sitemap.php

点击查看,即可查看sitemap.xml,也可以到根目录查看sitemap.xml

你可能感兴趣的:(wordpress,php)