Hi,

this might help someone who got problems with google sitemaps.

As I've seen there can arise two problems with "/catalog/view/theme/default/template/feed/google_sitemap.tpl"

1.) If you've have activated in "php.ini" the short_open_tag you'll get a php error. To solve this change the first line of the script to:

echo '<'.'?xml version="1.0" encoding="utf-8"?'.'>';
?>

2.) For sure you'l get an error at web-webmaster moaning about bad time stamp. to solve this change the whole script to:






$datetime = new DateTime($result['date']);
echo $datetime->format('Y-m-d\TH:i:sP'); ?>


echo $datetime->format('Y-m-d\TH:i:sP');
?>


weekly



0.5












I hope this helps

Hermann
In SEO
Thursday, December 03 2015, 03:04 PM
Share this post:

Accepted Answer

Sunday, December 06 2015, 03:10 PM - #Permalink
Hi Michael,

thanks for being "Know it all" and smart. I just posted this short_open_tag issue only for people like me which do not know nothing.

But the important issue in this case is the time format which you might have known too, but missing to write a smart commend about it.
The reply is currently minimized Show
Responses (7)
  • Accepted Answer

    Thursday, December 03 2015, 03:09 PM - #Permalink
    I'm sorry, but the Forum strips the PHP code, but you can see where the problem arise and change the related lines.

    Hermann
    The reply is currently minimized Show
  • Accepted Answer

    Friday, December 04 2015, 10:34 AM - #Permalink
    Hermann, can you please add the code again by using the code button of the editor?
    The reply is currently minimized Show
  • Accepted Answer

    Friday, December 04 2015, 02:53 PM - #Permalink
    Here it is again:

    <?php
    echo '<'.'?xml version="1.0" encoding="utf-8"?'.'>';
    ?>
    <urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:image="http://www.google.com/schemas/sitemap-image/1.1">
    <?php foreach ($results as $result) { ?>
    <url>
    <loc><?php echo $result['url']; ?></loc>
    <?php if (isset($result['date'])) { ?>
    <lastmod><?php
    $datetime = new DateTime($result['date']);
    echo $datetime->format('Y-m-d\TH:i:sP'); ?></lastmod>
    <?php } else { ?>
    <lastmod><?php $datetime = new DateTime(date('Y-m-d'));
    echo $datetime->format('Y-m-d\TH:i:sP');
    ?></lastmod>
    <?php } ?>
    <changefreq>weekly</changefreq>
    <?php if (isset($result['prior'])) { ?>
    <priority><?php echo $result['prior']; ?></priority>
    <?php } else { ?>
    <priority>0.5</priority>
    <?php } ?>
    <?php if (isset($result['img'])) { ?>
    <image:image>
    <image:loc><?php echo $result['img']; ?></image:loc>
    <image:caption><?php echo $result['name']; ?></image:caption>
    <image:title><?php echo $result['name']; ?></image:title>
    </image:image>
    <?php } ?>
    </url>
    <?php } ?>
    </urlset>
    The reply is currently minimized Show
  • Accepted Answer

    Friday, December 04 2015, 11:25 PM - #Permalink
    Thanks Hermann, will be available in the next version ;) https://github.com/arastta/arastta/issues/272
    The reply is currently minimized Show
  • Accepted Answer

    Friday, December 04 2015, 11:36 PM - #Permalink
    While the change may be good, but having
    1.) If you've have activated in "php.ini" the short_open_tag you'll get a php error. 
    is deprecated since many years!
    Why should one have open_tags??
    The reply is currently minimized Show
  • Accepted Answer

    Friday, December 04 2015, 11:51 PM - #Permalink
    Good point Michael.

    short_open_tag was used to enable the usage of a tag which is now enabled by default since PHP 5.4

    While there are very hot discussions about the usage of short tags, I was not able to find any warning about depreciation.
    The reply is currently minimized Show
  • Accepted Answer

    Saturday, December 05 2015, 10:56 AM - #Permalink
    We had at Joomla about 10 years ago a discussion about short_tags.

    Important is that here http://php.net/manual/en/ini.core.php#ini.short-open-tag
    If you want to use PHP in combination with XML, you can disable this option in order to use inline. Otherwise, you can print it with PHP, for example: '; ?>.


    The moment you use xml files (and that is what Joomla, Arastta, OC and nearly all other system I know using), short_tags should be avoided.

    I for myself have never used short_tags and I am using php since 17 years.
    Maybe I was wrong with the 'deprecated' because having in mind the troubles enabled short_tags can lead.
    Nevertheless, this code changing wont worry nobody ..
    The reply is currently minimized Show
Your Reply