ยินดีต้อนรับคุณ, บุคคลทั่วไป กรุณา เข้าสู่ระบบ หรือ ลงทะเบียน

เข้าสู่ระบบด้วยชื่อผู้ใช้ รหัสผ่าน และระยะเวลาในเซสชั่น

ThaiSEOBoard.comความรู้ทั่วไปSearch Engine Optimization(แจก).code.สร้าง sitemap.xml อัตโนมัติ (ถูกใจบวกให้ด้วยนะคับ)
หน้า: [1]   ลงล่าง
พิมพ์
ผู้เขียน หัวข้อ: (แจก).code.สร้าง sitemap.xml อัตโนมัติ (ถูกใจบวกให้ด้วยนะคับ)  (อ่าน 2762 ครั้ง)
0 สมาชิก และ 1 บุคคลทั่วไป กำลังดูหัวข้อนี้
personloans
ก๊วนเสียว
*

พลังน้ำใจ: 31
ออฟไลน์ ออฟไลน์

กระทู้: 388



ดูรายละเอียด เว็บไซต์
« เมื่อ: 17 ธันวาคม 2011, 23:20:22 »

วิธีคือคัดลอกโคตนี้แล้วบันทึกเป็นไฟน์ .php เช่น create_sitemap.php  แล้วอัพขึ้นโฮสที่ root
เวลาใช้งานก็เรียกตามนั้น เช่น เว็บชื่อ หล่อจังดอทคอม   เวลาเรียกก็  หล่อจังดอทคอม/create_sitemap.php
แล้วกดสร้างเลย พอสร้างเสร็จก็จะได้ไฟน์ sitemap.xml มาอัตโนมัติครับ
ปล.ไม่ได้เขียนเองนะคับ  พอดีไปเจอมา Tongue ถูกใจบวกให้ด้วยนะคับ
โค๊ด:
<?php
/******************************************************************************\
 * Author : Binny V Abraham                                                   *
 * Website: http://www.bin-co.com/                                            *
 * E-Mail : binnyva at gmail                                                  *
 * Get more PHP scripts from http://www.bin-co.com/php/                       *
 ******************************************************************************
 * Name    : PHP Google Search Sitemap Generator                              *
 * Version : 1.00.A                                                           *
 * Date    : Friday 17 November 2006                                          *
 * Page    : http://www.bin-co.com/php/programs/sitemap_generator/   *
 *                                                                            *
 * You can use this script to create the sitemap for your site automatically. *
 *  The script will recursively visit all files on your site and create a *
 *  sitemap XML file in the format needed by Google.   *
 *                                                                            *
 * Get more PHP scripts from http://www.bin-co.com/php/                       *
\******************************************************************************/

// Please edit these values before running your script.
//////////////////////////////////// Options ////////////////////////////////////
$url "http://www.thepayday-loans.com/"//The Url of the site - the last &#39;/&#39; is needed

$root_dir = &#39;/home/theonevi/public_html&#39;; //Where the root of the site is with relation to this file.

$file_mask = &#39;*.php&#39;; //Or *.html or whatever - Any pattern that can be used in the glob() php function can be used here.

//The file to which the result is written to - must be writable. The file name is relative from root.
$sitemap_file = &#39;sitemap.xml&#39;; 

// Stuff to be ignored...
//Ignore the file/folder if these words appear in the name
$always_ignore = array(
&#39;local_common.php&#39;,&#39;images&#39;,&#39;wiki&#39;
);

//These files will not be linked in the sitemap.
$ignore_files = array(
&#39;404.php&#39;,&#39;error.php&#39;,&#39;configuration.php&#39;,&#39;include.inc&#39;,&#39;BingSiteAuth.xml&#39;,&#39;create_sitemap.php&#39;,&#39;default.html&#39;,&#39;error_log&#39;,&#39;fsg-upload-141801179263.php&#39;,&#39;style.css&#39;
);

//The script will not enter these folders
$ignore_folders = array(
&#39;Waste&#39;,&#39;php_uploads&#39;,&#39;images&#39;,&#39;includes&#39;,&#39;lib&#39;,&#39;js&#39;,&#39;css&#39;,&#39;styles&#39;,&#39;system&#39;,&#39;stats&#39;,&#39;CVS&#39;,&#39;.svn&#39;,&#39;greatpaydayloans.us&#39;,&#39;cgi-bin&#39;
);

//The default priority for all pages - the priority of all pages will increase/decrease with respect to this.
$starting_priority = ($_REQUEST[&#39;starting_priority&#39;]) ? $_REQUEST[&#39;starting_priority&#39;] : 70;

/////////////////////////// Stop editing now - Configurations are over ////////////////////////////


///////////////////////////////////////////////////////////////////////////////////////////////////
function generateSiteMap() {
global $url$file_mask$root_dir$sitemap_file$starting_priority;
global $always_ignore$ignore_files$ignore_folders;
global $total_file_count,$average$lowest_priority_page$lowest_priority;

/////////////////////////////////////// Code ////////////////////////////////////
chdir($root_dir);
$all_pages getFiles(&#39;&#39;);

$xml_string = &#39;<?xml version="1.0" encoding="UTF-8"?>

<urlset
  xmlns="http://www.google.com/schemas/sitemap/0.84"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://www.google.com/schemas/sitemap/0.84
                      http://www.google.com/schemas/sitemap/0.84/sitemap.xsd">

';

$modified_priority = array();
for ($i=30;$i>0;$i--) array_push($modified_priority,$i);

$lowest_priority = 100;
$lowest_priority_page = "";
//Process the files
foreach ($all_pages as $link) {
//Find the modified time.
$handle = fopen($link,'r');
$info = fstat($handle);
fclose($handle);
$modified_at = date('Y-m-d\Th:i:s\Z',$info['mtime']);
$modified_before = ceil((time() - $info['mtime']) / (60 * 60 * 24));

$priority = $starting_priority; //Starting priority

//If the file was modified recently, increase the importance
if($modified_before < 30) {
$priority += $modified_priority[$modified_before];
}

if(preg_match('/index\.\w{3,4}$/',$link)) {
$link = preg_replace('/index\.\w{3,4}$/',"",$link);
$priority += 20;
}

//These priority detectors should be different for different sites :TODO:
if(strpos($link,'example')) $priority -= 30; //If the page is an example page
elseif(strpos($link,'demo')) $priority -= 30;
if(strpos($link,'tuorial')) $priority += 10;
if(strpos($link,'script')) $priority += 5;
if(strpos($link,'other') !== false) $priority -= 20;

//Priority based on depth
$depth = substr_count($link,'/');
if($depth < 2) $priority += 10; // Yes, I know this is flawed.
if($depth > 2) $priority += $depth * 5; // But the results are better.

if($priority > 100) $priority = 100;
$loc = $url . $link;
if(substr($loc,-1,1) == '/') $loc = substr($loc,0,-1);//Remove the last '/' char.


$total_priority += $priority;
if($lowest_priority > $priority) {
$lowest_priority = $priority;//Find the file with the lowest priority.
$lowest_priority_page = $loc;
}

$priority = $priority / 100; //The priority is given in decimals

$xml_string .= " <url>
  <loc>$loc</loc>
  <lastmod>$modified_at</lastmod>
  <priority>$priority</priority>
 </url>\n";
}

$xml_string .= "</urlset>";
if(!$hndl = fopen($sitemap_file,'w')) {
//header("Content-type:text/plain");
print "Can't open sitemap file - '$sitemap_file'.\nDumping result to screen...\n<br /><br /><br />\n\n\n";
print '<textarea rows="25" cols="70" style="width:100%">'.$xml_string.'</textarea>';
} else {
print '<p>Sitemap was written to <a href="' . $url.$sitemap_file .'">'. $url.$sitemap_file .'></a></p>';

fputs($hndl,$xml_string);
fclose($hndl);
}

$total_file_count = count($all_pages);
$average = round(($total_priority/$total_file_count),2);
}

///////////////////////////////////////// Functions /////////////////////////////////
// File finding function.
function getFiles($cd) {
$links = array();
$directory = ($cd) ? $cd . '/' : '';//Add the slash only if we are in a valid folder

$files = glob($directory . $GLOBALS['file_mask']);
foreach($files as $link) {
//Use this only if it is NOT on our ignore lists
if(in_array($link,$GLOBALS['ignore_files'])) continue;
if(in_array(basename($link),$GLOBALS['always_ignore'])) continue;
array_push($links, $link);
}
//asort($links);//Sort 'em - to get the index at top.

//Get All folders.
$folders = glob($directory . '*',GLOB_ONLYDIR);//GLOB_ONLYDIR not avalilabe on windows.
foreach($folders as $dir) {
//Use this only if it is NOT on our ignore lists
$name = basename($dir);
if(in_array($name,$GLOBALS['always_ignore'])) continue;
if(in_array($dir,$GLOBALS['ignore_folders'])) continue;

$more_pages = getFiles($dir); // :RECURSION:
if(count($more_pages)) $links = array_merge($links,$more_pages);//We need all thing in 1 single dimentional array.
}

return $links;
}

//////////////////////////////// Display /////////////////////////////


?>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.1 Transitional//EN">
<html>
<head>
<title>Sitemap Generation Using PHP</title>
<style type="text/css">
a {color:blue;text-decoration:none;}
a:hover {color:red;}
</style>
</head>
<body>
<h1>PHP Google Search Sitemap Generator Script</h1>

<?php
if($_POST[&#39;action&#39;] == &#39;Create Sitemap&#39;) {
generateSiteMap();
?>

<h2>Sitemap Created...</h2>

<h2>Statastics</h2>

<p><strong><?php echo $total_file_count?></strong> files were found and indexed.<br />
Lowest priority of <strong><?php echo $lowest_priority?></strong> was
given to <a href='<?php echo $lowest_priority_page?>'><?php echo $lowest_priority_page?></a></p>

Average Priority : <strong><?php echo $average?></strong><br />

<h2>Redo</h2>
<?php } else { ?>

<p>You can use this script to create the sitemap for your site automatically. The script will recursively visit all files on your site and create a sitemap XML file in the format needed by Google. </p>

<p>You can customize the result by changing the starting priorities.</p>
 
<h2>Set Starting Priority</h2>
<?php ?>

<form action="create_sitemap.php" method="post">
Starting Priority : <input type="text" name="starting_priority" size="3" value="<?php echo $starting_priority?>" />
<input type="submit" name="action" value="Create Sitemap" />
</form>

</body>
</html>
« แก้ไขครั้งสุดท้าย: 17 ธันวาคม 2011, 23:30:22 โดย personloans » บันทึกการเข้า

ab2f6
หัวหน้าแก๊งเสียว
*

พลังน้ำใจ: 49
ออฟไลน์ ออฟไลน์

กระทู้: 1,114



ดูรายละเอียด
« ตอบ #1 เมื่อ: 17 ธันวาคม 2011, 23:42:19 »

ผมลองทำมันเออเร่อครับ
บันทึกการเข้า

WPDSign
Verified Seller
เจ้าพ่อบอร์ดเสียว
*

พลังน้ำใจ: 500
ออฟไลน์ ออฟไลน์

กระทู้: 9,060



ดูรายละเอียด เว็บไซต์
« ตอบ #2 เมื่อ: 17 ธันวาคม 2011, 23:44:27 »

+1 ไปก่อนครับ
บันทึกการเข้า

สร้างบ้าน Modern แบบบ้านโมเดิร์น มาแรง
» ต้องการสร้างบ้านดูแบบบ้านสวยๆ แบบบ้านสองชั้น ทุกสไลต์บริการรับสร้างบ้าน ใครฝันอย่างสร้างบ้านสไตล์รีสอร์ท มีแบบบ้านสไตล์รีสอร์ท พร้อมก่อสร้าง ลงประกาศขายบ้านที่ ลงประกาศ
personloans
ก๊วนเสียว
*

พลังน้ำใจ: 31
ออฟไลน์ ออฟไลน์

กระทู้: 388



ดูรายละเอียด เว็บไซต์
« ตอบ #3 เมื่อ: 17 ธันวาคม 2011, 23:51:49 »

ผมลองทำมันเออเร่อครับ

ตรงช่องที่ใช่ตัวเลขด้านล่างครับ
ถ้ามันเอ๋อ  ก็ให้ลดลง ครับ
บันทึกการเข้า

bank_i3
ก๊วนเสียว
*

พลังน้ำใจ: 11
ออฟไลน์ ออฟไลน์

กระทู้: 474



ดูรายละเอียด เว็บไซต์
« ตอบ #4 เมื่อ: 18 ธันวาคม 2011, 00:51:08 »

ใครลองได้ แล้ว บอก มั่งนะงั้บ

ขอบคุณครับ ลอง ละ ไ่ม่ได้ อะ
บันทึกการเข้า

personloans
ก๊วนเสียว
*

พลังน้ำใจ: 31
ออฟไลน์ ออฟไลน์

กระทู้: 388



ดูรายละเอียด เว็บไซต์
« ตอบ #5 เมื่อ: 18 ธันวาคม 2011, 07:56:31 »

ใครลองได้ แล้ว บอก มั่งนะงั้บ

ขอบคุณครับ ลอง ละ ไ่ม่ได้ อะ

ไฟน์ต้องอยู่ใน host ที่อัพหน้าแรกนะคับ   เช่นพวกไฟน์ index.php หรือ index.html
ตรงช่อง Starting Priority ลองเปลี่ยนเป็นอย่างอื่นคับ เช่น 0.5   หรือ 1 ดูคับ
บันทึกการเข้า

pure126
ก๊วนเสียว
*

พลังน้ำใจ: 12
ออฟไลน์ ออฟไลน์

กระทู้: 281



ดูรายละเอียด เว็บไซต์
« ตอบ #6 เมื่อ: 22 มีนาคม 2012, 08:50:56 »

ขอบคุณครับ ขอลองหน่อย
บันทึกการเข้า

Luckyz
Verified Seller
สมุนแก๊งเสียว
*

พลังน้ำใจ: 85
ออฟไลน์ ออฟไลน์

กระทู้: 889



ดูรายละเอียด เว็บไซต์
« ตอบ #7 เมื่อ: 22 มีนาคม 2012, 09:09:54 »

ขอบคุณค่ะ  เก็บไว้ก่อน
+1 THANK ค่ะ
บันทึกการเข้า

TMY
ก๊วนเสียว
*

พลังน้ำใจ: 11
ออฟไลน์ ออฟไลน์

กระทู้: 300



ดูรายละเอียด
« ตอบ #8 เมื่อ: 22 มีนาคม 2012, 09:35:01 »

ถ้าติดตั้ง plugin google xml sitemap แล้ว ต้องใช้วิธีสร้าง sitemap แบบนี้ด้วยมั้ยครับ
บันทึกการเข้า

สร้างบทความง่ายๆด้วยโปรแกรม spinขั้นเทพเปลี่ยนรูปประโยคได้ อ่านรู้เรื่องที่สุด บทความ unique สุดๆ
หน้า: [1]   ขึ้นบน
พิมพ์