Plugin

Archived
Forum
(read-only)

Rein de Vries does not actively monitor this forum
(but you can still get help from other EE users).


For official support, visit the official support site »

Google Sitemap Lite

ExpressionEngine 2, ExpressionEngine 3

Back to this add-on's main page
View Other Add-ons From Rein de Vries

     

You must be logged in to post.

Sitemap dates contain invalid entry - “Array”

General (Resolved)

Trenbania
Trenbania

Hi,

A few (6 out of 452) entries in my sitemap are showing up as below - with incorrect lastmod:

<url>
<
loc>http://www.###.org/</loc>
<lastmod>Array</lastmod>
<
changefreq>daily</changefreq>
<
priority>0.5</priority>
</
url

Any ideas why this might happen - remaining 446 entries are fine!

EE 2.3.0 and Structure 3.0.4

Thanks
Andy

Reinos
# 1
Developer
Reinos

Hey, this is because the url_title from ExpressionEngine and the Structure of url_title are not the same.
If you change the url titles so that they are the same, everything go as it should be.

gl!

the Adsmith
# 2
the Adsmith

I was also able to fix this by changing the structure site map function to work off of the entry_id rather than the last url segment.

To implement this change you can go into pi.google_sitemap_lite.php
and replace the _struc_sitemap($data, $label) function with the following:

/**
  * Structure the data
  * 
  * @param $data
  * @param $label
  * @return unknown_type
  */
 
private function _struc_sitemap($data$label)
 
{
  
// Listing
  
if (preg_match("/Listing/i"$label)) {
   $listing 
true;
  
else {
   $listing 
false;
  
}
  
  $site_id 
$this->EE->config->item('site_id');
  
$site_pages $this->EE->config->item('site_pages');
  
$page_uris $site_pages[$site_id]['uris'];
  
$site_url $this->EE->config->item('site_url');

  if(!empty(
$data))
  
{
   
foreach($data as $val)
   
{

    
//Get page and listing Entry ids
    
$uri_segment str_replace($site_url''$val['url']);
    
$entry_id array_search($uri_segment$page_uris);


    
//get the last modified data
    
$sql "SELECT edit_date FROM exp_channel_titles WHERE entry_id = '".$entry_id."'";
    
$result $this->EE->db->query($sql);
    
$date $result->row();
    if(!empty(
$date->edit_date))
    
{
     $date 
date('Y-m-d',$this->EE->localize->timestamp_to_gmt($date->edit_date));
    
}


    
//format array
    
$this->site_map[] = array(
     
'loc' => $val['url'],
     
'lastmod' => $date,
     
'changefreq' => $listing?'weekly':'daily',
     
'priority' => $listing?'0.8':'0.5'
    
);

   
}
  }
 } 

This changes the function from using the last url segment, to doing a dynamic lookup against the pages system variable and returning the correct entry ids.

I found this fixed the problem for us.

Reinos
# 3
Developer
Reinos

Thanks for your research and your time for helping! I will check this week your code if it fits.

Reinos
# 4
Developer
Reinos

Just commit this change in v1.2.2. thanks for your help Adsmith :)