Build sitemap.xml for wordpress

8 February 2011 at 3:31 am Leave a comment

This tutorials is how to make make simple dynamic sitemap sitemap.xml WordPress with PHP. First, make a sitemap.xml file using notepad and then upload to your site directory (don’t forget to chmod 777). Make a sitemap.php file like this and upload too. Don’t forget to change db_user, db_password, db_name, and $site with your site and database details. You can change the limits too..

<?php
$user=”db_user”;
$host=”localhost”;
$password=”db_password”;
$database=”db_name”;

$connection = mysql_connect($host,$user,$password) or die (“Couldn’t connect to server”);
$db = mysql_select_db($database,$connection) or die (“Couldn’t select database”);

$sql = “SELECT * FROM wp_posts ORDER BY ID DESC LIMIT 0, 10000″;
$query = mysql_query($sql);

$site = http://www.articles2u.info/;

$_xml =”\r\n”;
$_xml .=”\r\n“;

$_xml .=”\t\r\n”;
$_xml .=”\t\t” . $site . “\r\n”;
$_xml .=”\t\tdaily\r\n”;
$_xml .=”\t\t1.0\r\n”;
$_xml .=”\t\r\n”;

while ($result = mysql_fetch_array($query)) {
$var = $result[‘guid’];

$_xml .=”\t\r\n”;
$_xml .=”\t\t” . $var .”\r\n”;
$_xml .=”\t\tmonthly\r\n”;
$_xml .=”\t\t0.5\r\n”;
$_xml .=”\t\r\n”;

}

$_xml .= “”;

$filename = “sitemap.xml”;
$filehandle = fopen(“./$filename”, ‘w’) or die(“Can’t open the file”);
fwrite($filehandle,$_xml);
fclose($filehandle);

echo “XML Sitemap Updated Successfully !!!”;

?>

Advertisements

Entry filed under: Blog and Website. Tags: , , .

Dork list for watching cctv all the world Search Engine Optimization (SEO) Tips for Prestashop

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Trackback this post  |  Subscribe to the comments via RSS Feed


Blog Stats

  • 56,171 hits
free counters


AziesT on Facebook


Yahoo bot last visit Msn bot last visit SEO Stats

Our Teams

Gudang Artikel AZIZALFIAN.COM

%d bloggers like this: