Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Welch08plt 4 posts 84 karma points
    Mar 08, 2017 @ 12:34
    Welch08plt
    0

    create dynamic images sitemap

    Hey, guys!

    I would like to ask for help on creating a dynamic sitemap for images. I found a similar code example https://our.umbraco.org/forum/umbraco-7/using-umbraco-7/75194-sitemap-for-images#comment-240683

    var list = Umbraco.TypedMediaAtRoot();
    
    foreach (var media in list)
    {
        if (media.Children != null && media.Children.Count() > 0)
        {
            foreach (var childMedia in media.Children)
            {
                <li><a href="@childMedia.Url">@childMedia.Name</a></li>
            }
        }
        else
        {
            <li><a href="@media.Url">@media.Name</a></li>
        }
    }
    

    But it's not complete, and I don`t understand what else to add to the template, Can anyone put on the right path?)

  • Alex Skrypnyk 6182 posts 24283 karma points MVP 8x admin c-trib
    Mar 08, 2017 @ 13:32
    Alex Skrypnyk
    0

    Hi Welch08plt

    Describe more please your images map?

    Do you want to show all images from umbraco Media section?

    How many levels do you have in Umbraco Media section?

    Thanks,

    Alex

  • Welch08plt 4 posts 84 karma points
    Mar 08, 2017 @ 15:37
    Welch08plt
    0

    Hi, Alex, thx you for responsiveness

    yes, want to show all my images and max level in Media section is 3.

  • Alex Skrypnyk 6182 posts 24283 karma points MVP 8x admin c-trib
    Mar 09, 2017 @ 16:48
    Alex Skrypnyk
    100

    Hi,

    Just wrote few lines of code, please try:

    @{
        var list = Umbraco.TypedMediaAtRoot();
    }
    
    <ul>
        @foreach (var rootMediaItem in list)
        {
            <li>
                @rootMediaItem.Name
                @if (rootMediaItem.DocumentTypeAlias.Equals("Folder") && rootMediaItem.Children != null && rootMediaItem.Children.Any())
                {
                    <ul>
                        @foreach (var level2 in rootMediaItem.Children)
                        {
                            <li>
                                @level2.Name
                                @if (level2.DocumentTypeAlias.Equals("Folder") && level2.Children != null && level2.Children.Any())
                                {
                                    <ul>
                                        @foreach (var level3 in level2.Children)
                                        {
                                            <li>@level3.Name</li>
                                        }
                                    </ul>
                                }
                            </li>
                        }
                    </ul>
                }
            </li>
        }
    </ul>
    

    Is it what you need?

    Thanks,

    Alex

  • Welch08plt 4 posts 84 karma points
    Mar 09, 2017 @ 17:38
    Welch08plt
    0

    hi, oh thx so much, it's work..

    But I incorrectly put it, and you also confused ... I would like to add pictures from all pages of the site, maybe you know how to do this?

  • Alex Skrypnyk 6182 posts 24283 karma points MVP 8x admin c-trib
    Mar 09, 2017 @ 17:40
    Alex Skrypnyk
    0

    Hi Welch08plt

    Yes, of course we can do it.

    So we need tree of pages? not media items?

    What alias of image property on your pages?

    Thanks,

    Alex

  • Welch08plt 4 posts 84 karma points
    Mar 09, 2017 @ 20:57
    Welch08plt
    0

    Need images link from the pages for xml image sitemap. Max level content section – 3. It would be wonderful if you help get the links, and I'll create the site map structure

    my structure

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies