Don't miss out Virtual Happy Hour this Friday (April 26).

Try our conversational search powered by Generative AI!

Sitemap MVC

Vote:
 

I'm wondering if there is a code sample using EPiServer Nuget 

Geta.SEO.Sitemaps 1.3.0.4

I want to be able to add to my project a sitemap page using this plugin, but I'm not sure how it works. It would be nice to have a step-by-step proces on how to develop this functionality.

Thanks in advance

#131356
Jul 22, 2015 0:40
Vote:
 

The sourcecode is available at GitHub since it is open source. Download/Clone the repository and have a look at it:

https://github.com/Geta/SEO.Sitemaps/

#140376
Oct 16, 2015 23:12
Vote:
 

Thank you Eric, I've been looking at GitHub Project, but not sure how to integrate this plugin to my project...so I asked for "step-by-step" process.

Neverless, I'll try it.

Regards

#140399
Oct 19, 2015 12:07
Vote:
 

Hi Antonio,

I recently used it for one of my client's project. It is fairly straight forward.

1. Get the nugest package, but beware, you need to download the right version from nuget using version command. In my case I had used it for Episerver 7.5 so  
I looked into version history to find out the right version compatible for 7.5.

2. Once the package is installed, you just need to compile your code and go to the CMS -> Admin Mode -> Search engine sitemap settings.

3. Click on the new sitemap button and add your site host name and it will generate the xml file for you.

4. Run the schedular service for it which is Generate search engine sitemaps.
    Make sure the service runs without error.

5. It will give you a view link when it is done. You need to jump back on to Search Engine sitemap settings underneath Tool.

You will also get related information under the Git link that is posted above.
Any question please ask. Hope this will help.

Cheers,
Naz

#140447
Edited, Oct 20, 2015 12:16
Vote:
 

Great,  Nazim Zia , thank you very much!!!

#140448
Oct 20, 2015 12:41
Vote:
 

The same goes for the source code except that you need to add that project to your solution and compile tha code. Once that is done and up and running you will be able to use it as mentioned above.

#140450
Oct 20, 2015 13:07
Vote:
 

I've followed the steps mentioned by Naz with success.

And now, last step: what must I do, to render a simple page with same links I'm seeing in the view link, from Search engine sitemap settings???

I need a page that users can see,  and can click the links to go to corresponding pages. I Apologize if it's obvious to you......but not to me.

Regards

#140454
Oct 20, 2015 13:42
Vote:
 

Hi Antonio.

Our package is for generating XML sitemaps that helps Google, Bing, Yahoo etc to crawl the site better. The package doesn't contain a page template with clickable links. That is something you would have to create by yourself.

This is a very simple code sample to get you started written out of my head. I haven't tested it at all:

public class MenuItem 
{
   public ContentReference ContentLink { get; set; }
   public IEnumerable<MenuItem> Children { get; set; }
}
[ContentType(DisplayName = "Sitemap", GUID = "73FC3DEE-BB8B-4874-B1BD-56BD5880F882")]
public class SitemapPage : PageData
{
   
}
public class SitemapView
{
   public IEnumerable<MenuItem> MenuItems { get; set; }
}
public class SitemapController : PageController<SitemapPage>
{
   private readonly EPiServer.Core.IContentLoader _contentLoader;

   public SitemapController(EPiServer.Core.IContentLoader contentLoader) 
   {
      _contentLoader = contentLoader;
   }

   public ActionResult Index(SitemapPage currentPage)
   {
      var model = new SitemapView
      {
         MenuItems = GetMenuItemsRecursive(EPiServer.Web.SiteDefinition.Current.StartPage)
      };

      return View(model);
   }

   private IEnumerable<MenuItem> GetMenuItemsRecursive(ContentReference contentLink)
   {
      var publishedFilter = new FilterPublished();
      var accessFilter = new FilterAccess();
      
      var menuItems = _contentLoader
         .GetChildren<PageData>(contentLink)
         .Where(p => p.VisibleInMenu && !publishedFilter.ShouldFilter(p) && !accessFilter.ShouldFilter(x))
         .Select(p => new MenuItem
         {
            ContentLink = p.ContentLink,
            Children = GetMenuItemsRecursive(p.ContentLink)
         });

      return menuItems;
   }
}

And in your view:

@model SitemapView

@helper SitemapMenuItem(MenuItem item, string itemCssClass, int currentDepth)
{
    <li class="@itemCssClass">
        @Html.ContentLink(item.ContentLink)
        
        @if (item.Children.Any())
        {
            <ul class="sitemap-submenu depth-@currentDepth">
                @foreach (var subItem in item.Children)
                {
                    @SitemapMenuItem(subItem, "sitemap-submenu-item", currentDepth + 1)
                }
            </ul>
        }
    </li>
}

<h1>Sitemap</h2>

<ul class="sitemap-menu">
   @foreach (var item in Model.MenuItems)
   {
      @SitemapMenuItem(item, "sitemap-menu-item", 1)
   }
</ul>
#140481
Edited, Oct 21, 2015 9:53
Vote:
 

Hi Antonio,

This is just the XML file generated and it can be used for search engines.
If you need a sitemap with all the active links on your website, you need to write some piece of code. You need to traverse through each children and display them as a link.

Hope it make sense.

Cheers,
Naz

#140482
Oct 21, 2015 9:55
Vote:
 

That's it Mattias, thank you!!!!!.....I just didn't understand exactly what the package is for.....

Cheers.

#140484
Oct 21, 2015 10:14
Vote:
 

Thanks Naz, now I understand better this package.

Cheers.

#140485
Oct 21, 2015 10:16
This topic was created over six months ago and has been resolved. If you have a similar question, please create a new topic and refer to this one.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.