kirby-xml-sitemap icon indicating copy to clipboard operation
kirby-xml-sitemap copied to clipboard

Only non-default page

Open illycz opened this issue 6 years ago • 4 comments

How do you solve the case, when you only need a non-default page on the web?

Thanks

illycz avatar Jan 29 '18 21:01 illycz

What do you mean by non-default page?

pedroborges avatar Jan 29 '18 23:01 pedroborges

Sorry i don't mention multilingual context... non-defult page = non-default language page.

illycz avatar Jan 29 '18 23:01 illycz

I also try to modify page generation to achieve https://support.google.com/webmasters/answer/2620865?hl=en

But foreach inside foreach not working and I don't know why :( I'm bad in PHP :)

<?php foreach ($languages as $lang) : ?>
<url>
    <loc><?= html($page->url($lang->code())) ?></loc>
    <lastmod><?= date('c', $page->modified()) ?></lastmod>

    <?php foreach ($languages as $lang) : ?>
    <xhtml:link hreflang="<?= $lang->code() ?>" href="<?= html($page->url($lang->code())) ?>" rel="alternate" />
    <?php endforeach ?>

    <?php if (c::get('sitemap.priority', false)) : ?>
    <priority><?= $page->priority() ?></priority>
    <?php endif ?>

    <?php if (c::get('sitemap.frequency', false)) : ?>
    <changefreq><?= $page->frequency() ?></changefreq>
    <?php endif ?>

    <?php if (c::get('sitemap.include.images', true) && $page->hasImages()) : ?>
    <?php foreach ($page->images() as $image) : ?>
    <?php snippet('sitemap.image', compact('image')) ?>
    <?php endforeach ?>
    <?php endif ?>
</url>
<?php endforeach ?>

illycz avatar Jan 29 '18 23:01 illycz

I am desperate. I'll try to explain what I'm trying to do.

I have two pages and three languages. So the sitemap should look like this (https://support.google.com/webmasters/answer/2620865?hl=en):

  • Homepage EN
    • Homepage EN as alternate
    • Homepage CZ as alternate
    • Homepage DE as alternate
  • Homepage CZ
    • Homepage EN as alternate
    • Homepage CZ as alternate
    • Homepage DE as alternate
  • Homepage DE
    • Homepage EN as alternate
    • Homepage CZ as alternate
    • Homepage DE as alternate
  • Subpage EN
    • Subpage EN as alternate
    • Subpage CZ as alternate
    • Subpage DE as alternate
  • Subpage CZ
    • Subpage EN as alternate
    • Subpage CZ as alternate
    • Subpage DE as alternate
  • Subpage DE
    • Subpage EN as alternate
    • Subpage CZ as alternate
    • Subpage DE as alternate

Your plugin actually display only:

  • Homepage EN
    • Homepage EN as alternate
    • Homepage CZ as alternate
    • Homepage DE as alternate
  • Subpage EN
    • Subpage EN as alternate
    • Subpage CZ as alternate
    • Subpage DE as alternate

This is a simplified example of page snippet:

<?php foreach ($languages as $lang) : ?>
<url>
    <loc><?= html($page->url($lang->code())) ?></loc>

    <?php foreach ($languages as $lang) : ?>
    <xhtml:link hreflang="<?= $lang->code() ?>" href="<?= html($page->url($lang->code())) ?>" rel="alternate" />
    <?php endforeach ?>
</url>
<?php endforeach ?>

Output is only and I don't know why:

  • Homepage EN
    • Homepage EN as alternate
    • Homepage CZ as alternate
    • Homepage DE as alternate
  • Subpage EN
    • Subpage EN as alternate
    • Subpage CZ as alternate
    • Subpage DE as alternate

When I remove the inner foreach, output is:

  • Homepage EN
  • Homepage CZ
  • Homepage DE
  • Subpage EN
  • Subpage CZ
  • Subpage DE

I tried to rename the variables but the output is still the same.

Do you have any idea how to solve this?

Thanks!

illycz avatar Jan 31 '18 14:01 illycz