+1-888-365-2779
Try Now
More in this section

Forums / Developing with Sitefinity / Blog Post Custom URLs

Blog Post Custom URLs

5 posts, 0 answered
  1. Jeff
    Jeff avatar
    11 posts
    Registered:
    23 Aug 2011
    21 Aug 2013
    Link to this post
    I found this article (custom_url_formats_for_sitefinity_content_modules) on specifying a custom URL format for news and blog posts.  However, after following the instructions, everything appears to be working except the URLs are unchanged.  I have the custom blog provider and a blog posts widget which displays the blogs created under that provider. 
    Here is the code I'm using (which is the same as from the article):
    public class BlogProviderNoDateUrls : OpenAccessBlogProvider
    {
        /// <summary>
        /// The URL format string for blog items
        /// </summary>
        public string BlogUrlFormat
        {
            get;
            set;
        }
     
        /// <summary>
        /// The URL format string for blog post items
        /// </summary>
        public string BlogPostUrlFormat
        {
            get;
            set;
        }
     
        public override string GetUrlFormat(Telerik.Sitefinity.GenericContent.Model.ILocatable item)
        {
            if (item.GetType() == typeof(Blog))
            {
                return this.BlogUrlFormat;
            }
            else if (item.GetType() == typeof(BlogPost))
            {
                return this.BlogPostUrlFormat;
            }
            else
            {
                return base.GetUrlFormat(item);
            }
        }
     
        protected override void Initialize(string providerName, System.Collections.Specialized.NameValueCollection config, Type managerType)
        {
            base.Initialize(providerName, config, managerType);
            this.BlogUrlFormat = config["blogUrlFormat"];
            if (String.IsNullOrEmpty(this.BlogUrlFormat))
            {
                this.BlogUrlFormat = "/[UrlName]";
            }
            this.BlogPostUrlFormat = config["blogPostUrlFormat"];
            if (String.IsNullOrEmpty(this.BlogPostUrlFormat))
            {
                this.BlogPostUrlFormat = "/[Parent.UrlName]/[PublicationDate, {0:yyyy'/'MM'/'dd}]/[UrlName]";
            }
        }
    }

    When I set a breakpoint in "GetUrlFormat" or "Initialize" I can see that these breakpoints are hit and the property "BlogPostUrlFormat" has the value I set for it in the parameter (which is “/[PublicationDate, {0:yyyy'/'MM'/'dd}]/[UrlName]").  The only difference is that Sitefinity didn't accept the value "/[UrlData]" for the blogUrlFormat parameter in the Sitefinity advanced configuration.  The result of trying to use that value was an error saying that value wasn't recognized.  So I used "/[UrlName]" as the value instead.

    *Note that another problem is that after changing the provider name on the blog posts widget, the list of blogs in the "From selected glogs only..." option is from the default provider, not the custom provider.  But choosing "From all blogs" does result in it displaying the blogs from the custom provider, so I am not too concerned about this problem yet.
  2. Kaloyan
    Kaloyan avatar
    272 posts
    Registered:
    08 Dec 2016
    23 Aug 2013
    Link to this post
    Hello Jeff,

    Thank you for contacting us.

    I have inspected the code sample and everything looks good. I have to try this solution on my test project and see if it is work for version 6.1. I will update you with information as soon as I have a result.

    Thank you for your patience.

    Regards,
    Kaloyan
    Telerik
    Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  3. Jeff
    Jeff avatar
    11 posts
    Registered:
    23 Aug 2011
    23 Aug 2013 in reply to Kaloyan
    Link to this post
    Thanks.

    Note that I am using Sitefinity 5.1.3450.0 for this web site.
  4. Marco
    Marco avatar
    11 posts
    Registered:
    19 Mar 2015
    09 Jun 2015
    Link to this post

    Hi all,

    I followed the steps. The thing is when we preview the draft or unpublished blog it throws a 404.

    The Sitefinity URL query rules for preview no longer show. Is there a fix for this?

  5. Marco
    Marco avatar
    11 posts
    Registered:
    19 Mar 2015
    09 Jun 2015 in reply to Jeff
    Link to this post
    I followed the steps. The thing is when we preview the draft or unpublished blog it throws a 404.
    The Sitefinity URL query rules for preview no longer show. Is there a fix for this?
5 posts, 0 answered