How to add blog posts to sitemap.xml?

Posted: May 19, 2017 at 10:07 PM Quote #188015
I'm trying to add blogPosts to the sitemap by adding following code in SitemapGenerator.cs

protected virtual IEnumerable<SitemapUrl> GetBlogUrls(UrlHelper urlHelp)
        {
            return _blogService.GetAllBlogPosts(storeId: 0, languageId: 0, dateFrom: null, dateTo: null, pageIndex: 0, pageSize: int.MaxValue, showHidden: false).Select (blog =>
            {
                var url = urlHelp.RouteUrl("Blog", new { blogPostId = blog.Id, SeName = blog.GetSeName() }, GetHttpProtocol());
                return new SitemapUrl(url, UpdateFrequency.Weekly, blog.CreatedOnUtc);
            });
        }

But the return result is
<url>
<loc>http://localhost/blog?blogPostId=3</loc>
<changefreq>weekly</changefreq>
<lastmod>2017-05-03</lastmod>
</url>
<url>
<loc>http://localhost/blog?blogPostId=1</loc>
<changefreq>weekly</changefreq>
<lastmod>2017-04-20</lastmod>
</url>

The return number is write, but not turn to the correct URLs.
Anyone help?

Thanks
This post/answer is useful
0
This post/answer is not useful

Please login or register
to vote for this post.

(click on this box to dismiss)
Posted: May 20, 2017 at 1:56 AM Quote #188021
zhugefs wrote:
I'm trying to add blogPosts to the sitemap by adding following code in SitemapGenerator.cs

protected virtual IEnumerable<SitemapUrl> GetBlogUrls(UrlHelper urlHelp)
        {
            return _blogService.GetAllBlogPosts(storeId: 0, languageId: 0, dateFrom: null, dateTo: null, pageIndex: 0, pageSize: int.MaxValue, showHidden: false).Select (blog =>
            {
                var url = urlHelp.RouteUrl("Blog", new { blogPostId = blog.Id, SeName = blog.GetSeName() }, GetHttpProtocol());
                return new SitemapUrl(url, UpdateFrequency.Weekly, blog.CreatedOnUtc);
            });
        }

But the return result is
<url>
<loc>http://localhost/blog?blogPostId=3</loc>
<changefreq>weekly</changefreq>
<lastmod>2017-05-03</lastmod>
</url>
<url>
<loc>http://localhost/blog?blogPostId=1</loc>
<changefreq>weekly</changefreq>
<lastmod>2017-04-20</lastmod>
</url>

The return number is write, but not turn to the correct URLs.
Anyone help?

Thanks


Try===>

protected virtual IEnumerable<SitemapUrl> GetBlogUrls(UrlHelper urlHelp)
        {
            return _blogService.GetAllBlogPosts(storeId: 0, languageId: 0, dateFrom: null, dateTo: null, pageIndex: 0, pageSize: int.MaxValue, showHidden: false).Select (blog =>
            {
                var url = urlHelp.RouteUrl("BlogPost", new { SeName= blog.GetSeName(blog.LanguageId, ensureTwoPublishedLanguages: false) }, GetHttpProtocol());
                return new SitemapUrl(url, UpdateFrequency.Weekly, blog.CreatedOnUtc);
            });
        }



Note: v3.9, others will similar too, may have some change on blog.GetSeName(blog.LanguageId, ensureTwoPublishedLanguages: false)
This post/answer is useful
0
This post/answer is not useful

Please login or register
to vote for this post.

(click on this box to dismiss)
Do you want to version upgrade, custom development, create plugins or need any help? You are welcome!
  Best Regards,
     Sohel
Email & Skype: [email protected]

http://nop-station.com/

Elasticsearch|Customize|Plugins|Themes|Upgrade|Server Setup(Hosting)|Consultancy|API
Posted: May 20, 2017 at 4:16 AM Quote #188026
Sohel, you are great, it works, thank you very much.

Z.
This post/answer is useful
0
This post/answer is not useful

Please login or register
to vote for this post.

(click on this box to dismiss)
Premium support services
  • Dedicated premium support services provided by core developers are intended for persons who run mission critical websites, work on projects with tight deadlines, or want to get dedicated support.
Professional services
  • Want to open a new store? Want to take your store to the next level? Need a custom extension? We can customize nopCommerce to fit your store perfectly. Request a quote to get started.
eCommerce CONFERENCE 2017
Learn more