Share mod auto site map, tags key cho wblib

Admin

AdminAdmin is verified member.

Well-Known Member
Staff member
Administrator
Đăng nhập host, tạo tập tin sitemap.php dán code này vào
Chạy domain/sitemap.php
PHP:
<?php
define('_WBLIB', 1);
include('inc/core.php');
$title = 'Tự động tạo sitemap, coder by tuoitreit.vn';
include('inc/head.php');
$xml_f = fopen('sitemap_baiviet.xml', 'w+');
$xml_c = fopen('sitemap_theloai.xml', 'w+');
$xml_index = fopen('sitemap.xml', 'w+');
$header_xml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<urlset xmlns=\"http://www.sitemaps.org/schemas/sitemap/0.9\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd\">\n";
$header = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<sitemapindex xmlns=\"http://www.sitemaps.org/schemas/sitemap/0.9\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd\">\n";
fwrite($xml_f, $header_xml);
fwrite($xml_c, $header_xml);
fwrite($xml_index, $header);
$req = mysql_query("SELECT `id`, `id_cat`, `name`, `time`, `java` FROM `article` WHERE `type`='2' ORDER BY `time` DESC");
if (!$req) die('Không thể đọc dữ liệu');
while ($res = mysql_fetch_assoc($req)) {
$cat = mysql_fetch_assoc(mysql_query("SELECT `name` FROM `article` WHERE `id` = '" . $res['id_cat'] . "'"));
$ftext = '<url>
<loc>' . $home . '/' . ga($cat['name']) . '/' . $res['id'] . '-' . ga($res['name']) . '.html</loc>
<lastmod>' . date('Y-m-d', $res['time']) . '</lastmod>
<changefreq>daily</changefreq>
<priority>1.0</priority>
</url>
';
if ($res['java'] == 1)
$ftext .= '<url>
<loc>' . $home . '/' . $res['id'] . '-' . ga($res['name']) . '-java.html</loc>
<lastmod>' . date('Y-m-d', $res['time']) . '</lastmod>
<changefreq>daily</changefreq>
<priority>1.0</priority>
</url>
';
fwrite($xml_f, $ftext);
}
mysql_free_result($req);
$req = mysql_query("SELECT `id`, `name` FROM `article` WHERE `type`='1' ORDER BY `id` DESC");
if (!$req) die('Không thể đọc dữ liệu');
while ($res = mysql_fetch_assoc($req)) {
$ftext = '<url>
<loc>' . $home . '/category/' . $res['id'] . '-' . ga($res['name']) . '.html</loc>
<lastmod>' . date('Y-m-d', $res['time']) . '</lastmod>
<changefreq>daily</changefreq>
<priority>0.8</priority>
</url>
';
fwrite($xml_c, $ftext);
}
$ftext = '<sitemap>
<loc>' . $home . '/sitemap_theloai.xml</loc>
<lastmod>' . date('Y-m-d') . '</lastmod>
</sitemap>
<sitemap>
<loc>' . $home . '/sitemap_baiviet.xml</loc>
<lastmod>' . date('Y-m-d') . '</lastmod>
</sitemap>
</sitemapindex>
';
fwrite($xml_index, $ftext);
$footer_xml = '</urlset>';
fwrite($xml_f, $footer_xml);
fwrite($xml_c, $footer_xml);
fclose($xml_f);
fclose($xml_c);
fclose($xml_index);
echo 'Bạo đã tạo sitemap thành công<br/><a href="sitemap.xml" title="Sitemap trang chủ">Trang chủ</a> <a href=sitemap_article.xml title="Sitemap bài viết">Bài viết</a> <a href=sitemap_category.xml title="Sitemap thể loại">Thể loại</a>';
include('inc/foot.php');
?>
Lưu lại là xong
Chúc các bạn thành công!
 
sevent Anh không còn giữ file nữa
 
Anh ơi khi nào em mới post được bài viêt có link :(
 

Facebook Comments

Similar threads

Admin
Replies
0
Views
3K
AdminAdmin is verified member.
Admin
Admin
Replies
0
Views
1K
AdminAdmin is verified member.
Admin
Admin
Replies
4
Views
989
boy94
boy94
Admin
Replies
0
Views
2K
AdminAdmin is verified member.
Admin
Admin
Replies
0
Views
803
AdminAdmin is verified member.
Admin
Back
Top