0

I created a template to customize labels views. But the fields are not displayed between labels.

Here are the views-view-field--sitemap--views-data-export--field-image.tpl.php :

<?php

$fields["field_image"]->content = '<image:loc>' . $field->original_value . '</image:loc>' . '<image:title>' . $row->field_field_image[0]['rendered']['#item']["alt"] . '</image:title>';

echo $fields["field_image"]->content;

and here are the views-data-export-xml-header--sitemap.tpl.php :

<?php print '<?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">'; 
?>

and the result :

<?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">  <url>
    <loc>http://www.s1biose.com/boutique/produit/savon-d-alep-artisanal-bio-pure-olive</loc>
    <image:image>&lt;image:loc&gt;http://www.s1biose.com/sites/default/files/image/boutique/savon-d-alep-artisanal-bio-pure-olive-photo-1.jpg&lt;/image:loc&gt;</image:image>
  </url>
  <url>
    <loc>http://www.s1biose.com/boutique/produit/savon-d-alep-artisanal-bio-5-de-laurier</loc>
</urlset>

The result should be :

<?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">
  <url>
    <loc>http://example-1.com/sample.html</loc>
    <image:image>
      <image:loc>http://example-1.com/image_1.jpg</image:loc>
      <image:title>title image 1</image:title>
    </image:image>
    <image:image>
      <image:loc>http://example-1.com/image_2.jpg</image:loc>
      <image:title>title image 2</image:title>
    </image:image>
  </url>
  <url>
    <loc>http://example-2.com/sample.html</loc>
    <image:image>
      <image:loc>http://example-2.com/image_1.jpg</image:loc>
      <image:title>title image 1</image:title>
    </image:image>
    <image:image>
      <image:loc>http://example-2.com/image_2.jpg</image:loc>
      <image:title>title image 2</image:title>
    </image:image>
  </url>
</urlset>
  • Is the template even used? Tried flushing caches? – dibs May 23 '16 at 23:25
  • try changing your first line to $fields["field_image"]->content = '<image:loc>' . $row->field_field_image[0]['rendered']['#item']["uri"] . '</image:loc>' . '<image:title>' . $row->field_field_image[0]['rendered']['#item']["alt"] . '</image:title>'; – No Sssweat May 24 '16 at 2:15
  • @No Sssweat :-) thank you it works but it displays 1 image instead of 3. There is also a problem with the url because it starts with "public: //" instead of "http: //" – user54067 May 24 '16 at 8:56
  • instead of three three ??? – No Sssweat May 24 '16 at 8:58
  • @No Sssweat yes – user54067 May 24 '16 at 9:06
1

you know how I can view the full URL of the image?

I found it, replace your 1st line with:

$fields["field_image"]->content = '<image:loc>' . $field->original_value . '</image:loc>' . '<image:title>' . $row->field_field_image[0]['rendered']['#item']["alt"] . '</image:title>';

thank you it works but it displays 1 image instead of 3

In views click on your image field, click on MULTIPLE FIELD SETTINGS uncheck display all values in the same row.

enter image description here

  • super thank you to the url complête it works. But for the image, you need the image belonging to the same node are grouped together. As in the last catch of the question. – user54067 May 25 '16 at 19:04
  • Google Search Console does not recognize the tags image:loc and image:title :( – user54067 May 26 '16 at 16:38
  • this is what it shows, just with the tag <image:loc> s1biose.com/sitemap-produit.xml – user54067 May 26 '16 at 17:13
  • 1
    I found this drupal.org/node/2061697 – user54067 May 26 '16 at 17:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy