Sitemap plugin

Find help with FlatPress plugins, report a plugin bug, request or present new plugins.
Post Reply
User avatar
AuroraZero
Posts: 3
Joined: Mon Feb 24, 2020 4:50 am

Sitemap plugin

Post by AuroraZero » Tue Feb 25, 2020 5:17 am

What has happened to sitemap plugin. It breaks everything when you enable it. I found an updated one, but it does the same now. I am not proficient enough to fix either of them yet. If some one has the time and can update it, that would be extremely useful, maybe just to me but others as well.

Tongara
Posts: 77
Joined: Wed Jan 22, 2020 11:09 am
Location: Birmingham, UK
Contact:

Re: Sitemap plugin

Post by Tongara » Thu Feb 27, 2020 6:55 am

I was never able to get the sitemap plugin working myself, but then after a bit of searching, I came across Igor Kromin's blog, in which he made his own sitemap code, and it couldn't be simpler to use (seriously, the guy is a master at Flatpress). The code I'll share below also includes his updated version of the code, which allows the sitemap to also index static page links after the blog entries. You can see his linked blog entry for more details on that.

First off, make a file called "sitemap.php" in the root of your flatpress install (where index.php is), and fill it with the following code:

Code: Select all

<?php
    require_once('defaults.php');
    require_once(INCLUDES_DIR.'includes.php');
    if (function_exists('system_init')) {
        system_init();
    }
    else {
        plugin_loadall();
    }
    header('Content-Type: text/xml; charset=utf-8');
    error_reporting(E_ALL);
    echo("<?");
?>xml version="1.0" encoding="UTF-8"<?php echo("?>"); ?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
  <url>
    <loc><?=BLOG_BASEURL?></loc>
    <lastmod><?=date("c");?></lastmod>
    <changefreq>daily</changefreq>
    <priority>1.0</priority>
  </url>
<?
    $q = new FPDB_Query(array('start'=>0, 'count'=>-1, 'fullparse'=>true), null);
    while($q->hasMore()) {
        list($id, $e) = $q->getEntry();
        $offset = $fp_config['locale']['timeoffset'];
        if (isset($e['lastupdate'])) {
                $lastmod = $e['lastupdate'] - (60 * 60 * $offset);
        }
        else {
                $lastmod = $e['date'] - (60 * 60 * $offset);
        }
        $loc =  BLOG_BASEURL . "index.php?x=entry:" . $id;
?>
  <url>
    <loc><?=$loc?></loc>
    <lastmod><?=date("c", $lastmod);?></lastmod>
  </url>
<?php
    }

$ss = static_getlist();
foreach($ss as $k => $val) {
  $s = static_parse($val);
  $i = BLOG_BASEURL . '?page=' . $val; 
  
  $offset = $fp_config['locale']['timeoffset'];
  $d = $s['date'] - (60 * 60 * $offset);
  
  $d = date('c', $d);
  echo('<url><loc>' . $i . '</loc><lastmod>' . $d . '</lastmod></url>');
}

?>
</urlset>
Simply save that, and in your browser, go to "YOUR-BLOG-URL.com/sitemap.php" and you'll have a fully generated sitemap.

Now, if you're using prettyurls, then the urs in the sitemap won't match what your blog url usually says... these links will still work, but you're using prettyurls for a reason, right?!

We can easily fix this by changing a single line of code. In your "sitemap.php" file, find the line that says:

Code: Select all

$loc =  BLOG_BASEURL . "index.php?x=entry:" . $id;
And change it to:

Code: Select all

$loc = get_permalink($id);
Then, if you want to remove "?page=" from the URLs of your static pages in the sitemap, simply find the line that says:

Code: Select all

$i = BLOG_BASEURL . '?page=' . $val;
And change it to:

Code: Select all

$i = BLOG_BASEURL . '' . $val; 
That should fix everything!

As an added part to this post, if you don't want to include Static pages for whatever reason, simply change:

Code: Select all

<?php
    }

$ss = static_getlist();
foreach($ss as $k => $val) {
  $s = static_parse($val);
  $i = BLOG_BASEURL . '?page=' . $val; 
  
  $offset = $fp_config['locale']['timeoffset'];
  $d = $s['date'] - (60 * 60 * $offset);
  
  $d = date('c', $d);
  echo('<url><loc>' . $i . '</loc><lastmod>' . $d . '</lastmod></url>');
}

?>
</urlset>
To:

Code: Select all

<?php
    }
?>
</urlset>
And that should be it! According to the original blog, this code generates a "Google compatible sitemap", which is what I think we're all pretty much after.
You can obviously go on to modify the code as you wish, but this is a good start, I think. :)

User avatar
AuroraZero
Posts: 3
Joined: Mon Feb 24, 2020 4:50 am

Re: Sitemap plugin

Post by AuroraZero » Mon Mar 02, 2020 3:30 pm

I appreciate this, but I tried the code from the same site and it totally borked my blog. I will give this code a go and see what happens, maybe it will work this time. If this works you may want to submit it to the wiki, so everyone can use it.

Tongara
Posts: 77
Joined: Wed Jan 22, 2020 11:09 am
Location: Birmingham, UK
Contact:

Re: Sitemap plugin

Post by Tongara » Mon Mar 02, 2020 5:54 pm

AuroraZero wrote: โ†‘Mon Mar 02, 2020 3:30 pm I appreciate this, but I tried the code from the same site and it totally borked my blog.
Considering this doesn't touch ANY code from your blog, it's impossible for it to do such, so it would be something else that is messing up your site. What exactly is happening to your site, and what is the error message (if any) you're getting?
I will give this code a go and see what happens, maybe it will work this time.
When it comes to this code, you literally just make a sitemap.php with it, and bam, it works. I can confirm it 100% works with a sitemap.php file I made minutes ago, and you can see that for yourself at: https://www.clockworkknight.com/flat/sitemap.php
If this works you may want to submit it to the wiki, so everyone can use it.
Sorry, but I don't really have time to be editing the wiki, as I have my own projects to deal with.
That said, the information is here and won't be going away any time soon, so feel free to add it to the wiki yourself, even if you just straight up copy and paste what I've written in my first response to you. Sky's the limit, etc!

User avatar
AuroraZero
Posts: 3
Joined: Mon Feb 24, 2020 4:50 am

Re: Sitemap plugin

Post by AuroraZero » Wed Mar 04, 2020 1:21 pm

I have reinstalled since then, and have not tried the code with it. It may have been an older version of this I tried, but none the less my site became completely inaccessible. Did not give an error code or anything just could not access it, and I was not the only one. All my monitoring went crazy telling me it was down, so I reinstalled.

Maybe today I will have a little time and try this out. I understand it does not do anything to the code of site. As I said before it may have been a different version, and maybe even a different author. my blog is mainly a venting area for me, and I just want Google/Bing/Yahoo etc.. to quit griping that there is no sitemap.

User avatar
Arvid
FlatPress Coder
Posts: 558
Joined: Sat Jan 26, 2019 7:40 pm
Contact:

Re: Sitemap plugin

Post by Arvid » Thu Apr 16, 2020 12:18 pm

Hi alltogether,

thanks for digging out that fine piece of Igor's code. I added a sitemap.php to the standard. Please feel free to get it here and test it: https://github.com/flatpressblog/flatpr ... itemap.php

Please let me know if that works correctly. It will later be part of the standard 1.2 distribution.

All the best,
Arvid

Post Reply

Who is online

Users browsing this forum: No registered users and 28 guests