FORUMS CLOSED DUE TO SPAM. YOU STILL CAN ADD POST!

Q. How to generate Sitemap ?

Feed 32 posts, 6 voices

Avatar
541 posts

create a snippet sitemap with filter set to none and body:

<?php
function snippet_sitemap($parent)
{
    $out = '';
    $childs = $parent->children();
    if (count($childs) > 0)
    {
        $out = '<ul>';
        foreach ($childs as $child)
            $out .= '<li>'.$child->link().snippet_sitemap($child).'</li>';
        $out.= '</ul>';
    }
    return $out;
}
?>
<div id="sitemap">
<?php echo snippet_sitemap($this->find('/')); ?>
</div>

in your sitemap page body, write: <?php $this->includeSnippet('sitemap'); ?> and use your Normal template

note: set your sitemap page hidden if you don't want it in your "sitemap".

 
Avatar
1493 posts

This is beautiful! :)) Thank you, Philippe!

 
Avatar
1493 posts

Just added this to the wiki with a bit of light editing.

 
Avatar
541 posts

if you want to include hidden pages just change $parent->children() by $parent->children(null, array(), true)

 
Avatar
41 posts

Hi there, by some reason I’m getting an error. The output I get is:

Parse error: syntax error, unexpected $end, expecting T_STRING or T_VARIABLE or '$' in /home/user/public_html/example.com/public/frog/app/frontend/classes/Page.php(192) : eval()'d code on line 1

Does anyone know what could it be? :S

 
Avatar
1493 posts

When you did your copy/paste, did you miss out the first < character??

 
Avatar
41 posts

I putted the code on a snipped and I called the snippet from the sitemap page. I’m getting the error with the html and the xml sitemaps (the xml of course, is with an xml layout).

html sitemap: http://indi.solubl.es/comic_sitemap
xml sitemap: http://indi.solubl.es/sitemap

I checked the tags, and none is left open…

 
Avatar
1493 posts

Weird one, Pnikosis! Can you copy/paste in your HTML snippet, and the code that calls it from the “comic_sitemap” page in the Frog pastebin. Not sure what else to suggest without seeing the code you’re using.

 
Avatar
41 posts

Pretty weird indeed. I’ve checked the code several times, and I can’t find anything. Anyway, here is the snippet pasted (the snipppet’s name is ‘sitemap’):

http://frog.pastebin.com/m95e9551

And the call:

http://frog.pastebin.com/m15255ba0

 
Avatar
1493 posts

Just a hunch — do you have a filter set on your Sitemap page? And if so, is it Textile? That gives me the identical error to yours with your code, which otherwise works fine when the Sitemap page has a filter of -none- or Markdown.

Hope that solves it!

 
Avatar
41 posts

David, you are right (I’m such a moron), I had the textile filter set on the page. I’ve checked everything but that.

Thanks again! If sometime you come to Spain I’ll invite you a couple (or more) of beers :)

 
Avatar
1493 posts

If sometime you come to Spain I’ll invite you a couple (or more) of beers :)

Sounds good to me! :P Glad it got sorted.

 
Avatar
35 posts

dies this trick work in 0.9.4 ?

$parent->children() by $parent->children(null, array(), true);

Doesn’t seem to return anything for me when i am finding children of a hidden page like this:

$this->find('hidden page')->children(null, array(), true);
 
Avatar
35 posts

ah, my mistake. As usual, frog works as expected and is rock solid. It’s nice to be able to count that the issue is me when it doesnt work.

$this->find('hidden-page')->children();

returns published pages of a hidden parent page, exactly what I wanted!

 
Avatar
22 posts

Can you show us the exact code you ended-up using as I need that same functionality for my sitemap since my site is split in two folders (multilanguage) and the folders are setup as hidden.

Thanks in advance.

 
Avatar
1493 posts

Hi 5ubstance: the line of code in the post above yours should be the working version. Try it, and if you have problems, let us know what they are!

 
Avatar
22 posts

I’m sure it works David, I’m just not sure about where it goes.

Should this be working :

<?php

 function snippet_xml_sitemap($parent)
 {
     $out = '';
     $childs = *$this->find('hidden-page')->children(null, array(), true);*
     if (count($childs) > 0)
     {
         foreach ($childs as $child)
        {
            $out .= "  <url>\n";
            $out .= "   <loc>".$child->url()."</loc>\n";
            $out .= "   <lastmod>".$child->date('%Y-%m-%d', 'updated')."</lastmod>\n";
            $out .= "   <changefreq>".($child->hasContent('changefreq') ? $child->content('changefreq'): 'weekly')."</changefreq>\n";
            $out .= "  </url>\n";
            $out .= snippet_xml_sitemap($child);
        }
    }
    return $out;
}

Cause it gives me this :

XML parsing failed: syntax error (Line: 3, Character: 0)
Reparse document as HTML
Error:unexpected end-of-file
Specification:http://www.w3.org/TR/REC-xml/
  1: <?xml version="1.0" encoding="UTF-8" ?> 
  2:  <urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
?>
<?php echo '<?'; ?>xml version="1.0" encoding="UTF-8" <?php echo '?>'; ?> 
 <urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
<?php echo snippet_xml_sitemap($this->find('/')); ?>
 </urlset>

I’m really not sure about where to place that code..

 
Avatar
1493 posts

Did you try using these instructions ? It looks to me like the page isn’t being properly recognized as XML.

 
Avatar
22 posts

Yeah, the code is fine if I don’t change anything. It’s working with philippe’s solution :

if you want to include hidden pages just change $parent->children() by $parent->children(null, array(), true)

but then, I need to do exactly what avagraphique did which is : return published pages of a hidden parent without the hidden parent itself, and then generate that list as a sitemap.

I hope I’ve explained myself correctly but if not, here are some screengrabs :

 
Avatar
1493 posts

I think the problem is where you are trying to set the root of your search. Set the “5th” line of the function back to the original:

$childs = $parent->children();

Then, at the end of the snippet code, change the echo routine so that the root of the search is set to your hidden page:

<?php echo snippet_xml_sitemap($this->find('fr')); ?>

and see how that works. (Then just change ('fr') to ('en') for the other part of your site, of course). Here’s hoping that does it!

 
Avatar
22 posts

David, you are a Frog CMS official ROCK STAR !!

Okay, maybe I’m exxagerating.. a LITTLE bit :P

Anyways, you opened my eyes with your last post. I just ended up copying that last segment and changing the roots to /fr/ and /en/ . Here’S what it looks like :

<?php

function snippet_xml_sitemap($parent)
{
    $out = '';
    $childs = $parent->children();

    if (count($childs) > 0)
    {
        foreach ($childs as $child)
        {
            $out .= "  <url>\n";
            $out .= "   <loc>".$child->url()."</loc>\n";
            $out .= "   <lastmod>".$child->date('%Y-%m-%d', 'updated')."</lastmod>\n";
            $out .= "   <changefreq>".($child->hasContent('changefreq') ? $child->content('changefreq'): 'weekly')."</changefreq>\n";
            $out .= "  </url>\n";
            $out .= snippet_xml_sitemap($child);
        }
    }
    if (count($hChilds) > 0)
    {
        foreach ($childs as $child)
        {
            $out .= "  <url>\n";
            $out .= "   <loc>".$child->url()."</loc>\n";
            $out .= "   <lastmod>".$child->date('%Y-%m-%d', 'updated')."</lastmod>\n";
            $out .= "   <changefreq>".($child->hasContent('changefreq') ? $child->content('changefreq'): 'weekly')."</changefreq>\n";
            $out .= "  </url>\n";
            $out .= snippet_xml_sitemap($child);
        }
    }
    return $out;
}
?>
<?php echo '<?'; ?>xml version="1.0" encoding="UTF-8" <?php echo '?>'; ?> 
 <urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
<?php echo snippet_xml_sitemap($this->find('/fr/')); ?>
<?php echo snippet_xml_sitemap($this->find('/en/')); ?>
 </urlset>

Thanks again David

p.s. the amount of posts you have right now really speaks for itself… :P

 
Avatar
7 posts

he is in the 1337