Jump to content

Recommended Posts

Posted

Marius Mailat prezinta o solutie de generare a unui sitemap in PHP. In exemplu ne este dat un site cu peste 200.000 de pagini si care va avea in jur de 40 de sitemap-uri.

Cum se face generarea ? Cu codul de mai jos:

<?php

//include baza de date

$db=mysql_connect($dbhost,$dbuser,$dbpass);

mysql_select_db($dbdatabase);

$mainPages = array(

"http://www.domeniu.ro/",

"http://www.domeniu.ro/topuseri/",

"http://www.domeniu.ro/toparticole/");

//declara header si insceput sitemap

header ('Content-type: text/xml');

echo '<?xml version="1.0" encoding="ISO-8859-1" ?>';

echo '<urlset xmlns="http://www.google.com/schemas/sitemap/0.84"'>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">';

for($i=0; $i<count($mainPages); $i++){

echo '<url>

<loc>'. $mainPages[$i] .'</loc>

<changefreq>daily</changefreq>

<priority>1.0</priority>

</url>';

}

//genereaza categoriile

$map_result = mysql_query("SELECT id FROM categorii");

while ($map_row = mysql_fetch_array($map_result)) {

$category = "http://www.domeniu.ro/categorie/" . $map_row['id'] . "/";

echo "

<url>

<loc>". $category ."</loc>

<changefreq>weekly</changefreq>

<priority>1.0</priority>

</url>";

}

//genereaza elementele

$map_result = mysql_query("SELECT id FROM articole WHERE aprobat = 1??€

Te-ai inregistrat? Ne-ar placea sa te prezinti.

Cum pot sustine forumul?
Cumpara de la eMag folosind acest link.
--------------------
oG2BN9d.gifse1WdXd.gifQG6MtmI.gifRHYjDzD.gifG5p1wui.gif

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.