Browse Source

Add author URL to sitemap

Add author URL to sitemap index.
pull/9/head
Danang Probo Sayekti 12 years ago
parent
commit
dcf9d5633c
2 changed files with 43 additions and 2 deletions
  1. +5
    -1
      system/htmly.php
  2. +38
    -1
      system/includes/functions.php

+ 5
- 1
system/htmly.php View File

@ -203,7 +203,7 @@ get('/search/:keyword', function($keyword){
// The static page // The static page
get('/:static', function($static){ get('/:static', function($static){
if($static === 'sitemap.xml' || $static === 'sitemap.base.xml' || $static === 'sitemap.post.xml' || $static === 'sitemap.static.xml' || $static === 'sitemap.tag.xml' || $static === 'sitemap.archive.xml') {
if($static === 'sitemap.xml' || $static === 'sitemap.base.xml' || $static === 'sitemap.post.xml' || $static === 'sitemap.static.xml' || $static === 'sitemap.tag.xml' || $static === 'sitemap.archive.xml' || $static === 'sitemap.author.xml') {
header('Content-Type: text/xml'); header('Content-Type: text/xml');
@ -225,8 +225,12 @@ get('/:static', function($static){
else if ($static === 'sitemap.archive.xml') { else if ($static === 'sitemap.archive.xml') {
generate_sitemap('archive'); generate_sitemap('archive');
} }
else if ($static === 'sitemap.author.xml') {
generate_sitemap('author');
}
die; die;
} }
$post = get_static_post($static); $post = get_static_post($static);


+ 38
- 1
system/includes/functions.php View File

@ -929,53 +929,69 @@ function generate_sitemap($str){
echo '<?xml version="1.0" encoding="UTF-8"?>'; echo '<?xml version="1.0" encoding="UTF-8"?>';
if ($str == 'index') { if ($str == 'index') {
echo '<sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">'; echo '<sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">';
echo '<sitemap><loc>' . site_url() . 'sitemap.base.xml</loc></sitemap>'; echo '<sitemap><loc>' . site_url() . 'sitemap.base.xml</loc></sitemap>';
echo '<sitemap><loc>' . site_url() . 'sitemap.post.xml</loc></sitemap>'; echo '<sitemap><loc>' . site_url() . 'sitemap.post.xml</loc></sitemap>';
echo '<sitemap><loc>' . site_url() . 'sitemap.static.xml</loc></sitemap>'; echo '<sitemap><loc>' . site_url() . 'sitemap.static.xml</loc></sitemap>';
echo '<sitemap><loc>' . site_url() . 'sitemap.tag.xml</loc></sitemap>'; echo '<sitemap><loc>' . site_url() . 'sitemap.tag.xml</loc></sitemap>';
echo '<sitemap><loc>' . site_url() . 'sitemap.archive.xml</loc></sitemap>';
echo '<sitemap><loc>' . site_url() . 'sitemap.archive.xml</loc></sitemap>';
echo '<sitemap><loc>' . site_url() . 'sitemap.author.xml</loc></sitemap>';
echo '</sitemapindex>'; echo '</sitemapindex>';
} }
elseif ($str == 'base') { elseif ($str == 'base') {
echo '<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">'; echo '<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">';
echo '<url><loc>' . site_url() . '</loc><changefreq>hourly</changefreq><priority>1.0</priority></url>'; echo '<url><loc>' . site_url() . '</loc><changefreq>hourly</changefreq><priority>1.0</priority></url>';
echo '</urlset>'; echo '</urlset>';
} }
elseif ($str == 'post') { elseif ($str == 'post') {
$posts = get_path(); $posts = get_path();
echo '<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">'; echo '<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">';
foreach($posts as $p) { foreach($posts as $p) {
echo '<url><loc>' . $p->url . '</loc><changefreq>monthly</changefreq><priority>0.5</priority></url>'; echo '<url><loc>' . $p->url . '</loc><changefreq>monthly</changefreq><priority>0.5</priority></url>';
} }
echo '</urlset>'; echo '</urlset>';
} }
elseif ($str == 'static') { elseif ($str == 'static') {
$posts = get_static_path(); $posts = get_static_path();
echo '<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">'; echo '<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">';
foreach($posts as $p) { foreach($posts as $p) {
echo '<url><loc>' . $p->url . '</loc><changefreq>monthly</changefreq><priority>0.5</priority></url>'; echo '<url><loc>' . $p->url . '</loc><changefreq>monthly</changefreq><priority>0.5</priority></url>';
} }
echo '</urlset>'; echo '</urlset>';
} }
elseif ($str == 'tag') { elseif ($str == 'tag') {
$posts = get_path(); $posts = get_path();
$tag = array(); $tag = array();
foreach($posts as $p) { foreach($posts as $p) {
$tag[] = $p->tagurl; $tag[] = $p->tagurl;
} }
$tag = array_unique($tag, SORT_REGULAR); $tag = array_unique($tag, SORT_REGULAR);
echo '<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">'; echo '<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">';
foreach($tag as $t) { foreach($tag as $t) {
echo '<url><loc>' . $t . '</loc><changefreq>weekly</changefreq><priority>0.5</priority></url>'; echo '<url><loc>' . $t . '</loc><changefreq>weekly</changefreq><priority>0.5</priority></url>';
} }
echo '</urlset>'; echo '</urlset>';
} }
elseif ($str == 'archive') { elseif ($str == 'archive') {
@ -1010,6 +1026,27 @@ function generate_sitemap($str){
} }
echo '</urlset>'; echo '</urlset>';
}
elseif ($str == 'author') {
$posts = get_path();
$author = array();
foreach($posts as $p) {
$author[] = $p->authorurl;
}
$author = array_unique($author, SORT_REGULAR);
echo '<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">';
foreach($author as $a) {
echo '<url><loc>' . $a . '</loc><changefreq>daily</changefreq><priority>0.5</priority></url>';
}
echo '</urlset>';
} }
} }


Loading…
Cancel
Save