Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Only non-default page #12

Open
illycz opened this issue Jan 29, 2018 · 4 comments
Open

Only non-default page #12

illycz opened this issue Jan 29, 2018 · 4 comments

Comments

@illycz
Copy link

illycz commented Jan 29, 2018

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

Thanks

@pedroborges
Copy link
Owner

What do you mean by non-default page?

@illycz
Copy link
Author

illycz commented Jan 29, 2018

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

@illycz
Copy link
Author

illycz commented Jan 29, 2018

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
Copy link
Author

illycz commented Jan 31, 2018

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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants