Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

generating a dynamic url sitemap #10

Open
mariangiuglea opened this issue Jul 9, 2018 · 1 comment
Open

generating a dynamic url sitemap #10

mariangiuglea opened this issue Jul 9, 2018 · 1 comment

Comments

@mariangiuglea
Copy link

Hello, I have a problem generating a dynamic url sitemap. My URL is https://apartamente-24.ro/#!/posts/Apartament-5-camere-Cars-Brasov/19. Where: Apartment-5-rooms-Center-Brasov is the title saved in the database. And 19 is id. Unfortunately, now I only export my id or title not both.

connect_error) { die("Connection failed: " . $conn->connect_error); } $query = "SELECT $column_name FROM $table_name"; $result = mysqli_query($conn, $query); $dom = new DomDocument('1.0', 'UTF-8'); $root = $dom->appendChild($dom->createElement('urlset')); $attr = $dom->createAttribute('xmlns'); $attr->appendChild($dom->createTextNode('http://www.sitemaps.org/schemas/sitemap/0.9')); $root->appendChild($attr); $count = 0; foreach ($static_pages as $page ) { generate_elements($page); } while ($row = mysqli_fetch_assoc( $result) ) { $curr = $row[$column_name]; generate_elements($curr); } echo "

In sitemap au fost generate : $count

"; $dom->formatOutput = true; $test1 = $dom->saveXML(); $dom->save('sitemap_forum.xml'); function generate_elements($curr){ global $base_url,$frequency,$root,$dom,$count; $url = $dom->createElement('url'); $root->appendChild($url); $loc = $dom->createElement('loc',$base_url.$curr); $url->appendChild($loc); $lastmod = $dom->createElement('lastmod',date("Y-m-d")); $url->appendChild($lastmod); $changefreq = $dom->createElement('changefreq',$frequency); $url->appendChild($changefreq); $priority = $dom->createElement('priority',1); $url->appendChild($priority); $count++; } ?>
@mariangiuglea
Copy link
Author

`<?php
// CONFIGURATION
// Set a password to limit access to generating XML's
$token = "aaa";
// Set your MySQL details
$servername="aaa";
$username="aaa";
$password="aaa";
$dbname="aaa";
// Set your custom table name to generate
$table_name = "Posts";
// Set your custom column name to generate
$column_name = "title, id";
// Your site Base URL
$base_url = "https://apartamente-24.ro/sfaturi-din-imobiliare/#!/posts/";
$frequency = "daily";
// These are the static/page/subdirectories you need to include in the site map
$static_pages = array("","index.html");

// END CONFIGURATION
if($_GET["token"] != $token){
die("Not Authorized");
}
$conn = new mysqli($servername, $username, $password, $dbname);
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$query = "SELECT $column_name FROM $table_name";
$result = mysqli_query($conn, $query);
$dom = new DomDocument('1.0', 'UTF-8');
$root = $dom->appendChild($dom->createElement('urlset'));
$attr = $dom->createAttribute('xmlns');
$attr->appendChild($dom->createTextNode('http://www.sitemaps.org/schemas/sitemap/0.9'));
$root->appendChild($attr);
$count = 0;
foreach ($static_pages as $page ) {
generate_elements($page);
}
while ($row = mysqli_fetch_assoc( $result) ) {
$curr = $row[$column_name];
generate_elements($curr);
}
echo "

In sitemap au fost generate : $count

";
$dom->formatOutput = true;
$test1 = $dom->saveXML();
$dom->save('sitemap_forum.xml');
function generate_elements($curr){
global $base_url,$frequency,$root,$dom,$count;
$url = $dom->createElement('url');
$root->appendChild($url);
$loc = $dom->createElement('loc',$base_url.$curr);
$url->appendChild($loc);
$lastmod = $dom->createElement('lastmod',date("Y-m-d"));
$url->appendChild($lastmod);
$changefreq = $dom->createElement('changefreq',$frequency);
$url->appendChild($changefreq);
$priority = $dom->createElement('priority',1);
$url->appendChild($priority);
$count++;
}
?> `

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

1 participant