Copied to clipboard

Flag this post as spam?

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


  • Genc Kastrati 46 posts 269 karma points
    May 29, 2017 @ 14:21
    Genc Kastrati
    0

    Approaches to generating Google Sitemap automatically

    Hello everyone,

    I did a quick search on the forum about Google Sitemap generation and found a few older posts and was wondering if anyone has any newer ways to generate a Google Sitemap on Umbraco?

    Thank you! Genc

  • MuirisOG 331 posts 1104 karma points
    May 29, 2017 @ 18:00
    MuirisOG
    0

    Have you tried editing a template in the backoffice, and selecting the option to include one of the Umbraco pre-built macros. I'm sure they have a sitemap in there....

  • Kris Janssen 209 posts 567 karma points c-trib
    May 29, 2017 @ 19:18
    Kris Janssen
    100

    Something like this should do the trick nicely... (I think this even comes built-in):

    @inherits Umbraco.Web.Mvc.UmbracoTemplatePage
    @{
        Layout = null;
    
        //Set to XML
        Response.ContentType = "text/xml";
     }
     <?xml version="1.0" encoding="UTF-8" ?>
     <urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
     @{
         var homePage = CurrentPage.AncestorOrSelf(1);
    
         if (homePage != null && (homePage.Children.Any()))
         {
             <url>
                 <loc>@homePage.UrlWithDomain()</loc>
             </url>
             @Traverse(homePage, false)
         }
       }
      </urlset>
      @helper Traverse(IPublishedContent parent, bool newList)
      {
          var subPages = parent.Children.Where(x => x.IsVisible() && !x.HasProperty(DataNodePropertyAlias)).OrderBy(x => x.SortOrder);
          foreach (var page in subPages)
          {
              <url>
                  <loc>@page.UrlWithDomain()</loc>
              </url>
              @Traverse(page, true);
          }
       }
       @functions{
          private const string DataNodePropertyAlias = "isDataNode";
       }
    
  • Genc Kastrati 46 posts 269 karma points
    May 31, 2017 @ 09:52
    Genc Kastrati
    0

    hi Kris,

    I tried this and it worked. The only thing I modified was to use "Model.Content.Site()" instead of "CurrentPage.AncestorOrSelf(1)". As suggested here:

    https://our.umbraco.org/documentation/reference/Common-Pitfalls/

    Thank you! Genc

  • Genc Kastrati 46 posts 269 karma points
    May 30, 2017 @ 07:51
    Genc Kastrati
    0

    Thank you both! I will give this a try! Will update this post with news shortly! :D

  • MuirisOG 331 posts 1104 karma points
    May 30, 2017 @ 10:05
    MuirisOG
    0

    Here's a screenshot (in version 7.5.13) of the "Edit Template" screen in the backoffice. If you select the dropdown next to "Insert Inline Razor Macro", you'll see "Sitemap" as one of the options and this will insert the code you need.

    enter image description here

  • Genc Kastrati 46 posts 269 karma points
    May 30, 2017 @ 12:31
    Genc Kastrati
    0

    Thank you MuirisOG. It is very strange, but in 7.4.14 I do not have the pre-built macros you have. This isn't normal right?

    This is what I see: enter image description here

  • MuirisOG 331 posts 1104 karma points
    May 30, 2017 @ 12:48
    MuirisOG
    0

    That is strange.

    I've looked back at earlier versions of Umbraco that I have been working on, and found that I have the option under these versions:

    6.2.4, 7.3.0, 7.4.3 and 7.5.2
    

    I'm using Webforms, so I don't know if that would cause such a difference.

    Here's a screenshot from 6.2.4 enter image description here

  • Nicola Ayan 6 posts 75 karma points
    Mar 05, 2018 @ 10:47
    Nicola Ayan
    0

    This is how I was able to implement a dynamic sitemap on my Umbraco 7.7.9 installation:

    1. Create a Sitemap document type
    2. Create a Sitemap macro
    3. Create a rule for IIS URL rewriting of the sitemap.xml
    4. Author the Sitemap content page

    Step-by-step tutorial here: https://blog.nicolaayan.com/2018/03/generate-an-umbraco-sitemap/

  • Umbraco Newbie 22 posts 124 karma points
    14 days ago
    Umbraco Newbie
    0

    Hi Bit late to this post, but if anyone is looking for an example of how to do this using a controller, I have a blog post at https://www.georgephillipson.com/blog/umbraco/umbraco-xml-sitemap/ and it also contains code that can be downloaded from GitHub.

    Hope it helps someone

Please Sign in or register to post replies

Write your reply to:

Draft