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

Forums / Developing with Sitefinity / BlogPost Full URLs

BlogPost Full URLs

4 posts, 0 answered
  1. David Lamb
    David Lamb avatar
    10 posts
    Registered:
    02 Oct 2009
    15 Jun 2013
    Link to this post
    Re: Sitefinity 6.0, I need to build a highly customized canonical URL for my blog post detail views, with very specific rules that differ for each blog. (Six blogs on one site.) I have a custom code-behind for the BlogPost detail view, and I was hoping to use those rules to pick a given URL from the various pages that a given post is published to. (I published it via the "Blog posts" widget, filtering each list for blog and category.) That code-behind would manually create the LINK rel="canonical" tag and add it to the page header.

    I have discovered two challenges.

    1. I cannot get the list of pages that a given post is viewable on. The closest I can get is a list of pages that contain a BlogPostView control:
    App.WorkWith().Pages().Where(p => p.Page != null && p.WasPublished && p.Page.Controls.Where(c => c.ObjectType.StartsWith(typeof(BlogPostView).FullName)).Count() > 0).Get();

    2. The list that appears in the Admin panel when I edit the post ("Pages where this item can be found") would be the list of URLs that I'd like to try to pull, but that list itself isn't even accurate. Well, problematically, it IS accurate, because the URLs all work, but it SHOULDN'T be. It includes pages that the particular blog itself has not been published on, according to the properties that I set using the built-in "Blog posts" widget.

    Ultimately, I want to do something analagous to myBlogPost.GetFullUrls(), but that doesn't seem to be available to me.
  2. Kristian Smilenov
    Kristian Smilenov avatar
    32 posts
    Registered:
    18 Mar 2015
    18 Jun 2013
    Link to this post
    Hello David,

    Our documentation on Content Locations API is pending approval, and soon will be available in our documentation portal. Until then you need to know that you can use directly our ContentLocationService for retrieving the locations of a specific content. This is the part that gets item locations:

    GetItemLocations

    Get all locations where a specific item could be opened

    ·         GetItemLocations(Type itemType, string itemProvider, Guid itemId, CultureInfo culture = null) - Gets all locations where the specified item of type, provider, id and culture (for multilingual) could be opened. This method is useful when there is no reference to the actual content item. It returns an enumeration of IContentItemLocation objects. If there is no location – returns an empty collection.

    Example – get all URLs of an item created with the DynamicModule using its id:

    List<string> GetDynamicModuleItemUrls(Guid itemId)
    {
       List<string> result = new List<string>();
       var clService = SystemManager.GetContentLocationService();
       var allLocations = clService.GetItemLocations(typeof(MyDynamicModuleType), string.Empty, itemId);
      
       foreach (var location in allLocations)
       {
          //get all URLs of the item (even the default one)     
          result.Add(location.ItemAbsoluteUrl);
       }
      
       return result;
    }

    ·         GetItemLocations(IDataItem item, CultureInfo culture = null) - Gets all locations where the specified item. This method is useful when there is a reference to the actual content item. It returns an enumeration of IContentItemLocation objects. If there is no location – returns an empty collection.

    Example – get URLs of a dynamic module item:

    List<string> GetDynamicModuleItemUrls(MyDynamicModuleType item)
    {
       List<string> result = new List<string>();
       var clService = SystemManager.GetContentLocationService();
       var allLocations = clService.GetItemLocations(item);
      
       foreach (var location in allLocations)
       {
          //get all URLs of the item (even the default one)
          result.Add(location.ItemAbsoluteUrl);
       }
      
       return result;
    }

    You can set itemType to Telerik.Sitefinity.Blogs.Model.BlogPost, provider to OpenAccessDataProvider and 
    itemId to your blog post id.

    I hope this information is helpful to you.

    Regards,
    Kristian Smilenov
    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. David Lamb
    David Lamb avatar
    10 posts
    Registered:
    02 Oct 2009
    19 Jun 2013 in reply to Kristian Smilenov
    Link to this post
    Thank you, that worked. I now get the same list as displayed in the Admin panel. I'm still bothered, however, by my 2nd point... that the post is getting published to inappropriate URLs.

    When I add the BlogPosts widget to a page, and I only want to display posts from a specific blog and category, the other posts should not get published at that URL (/hostpage/blogPostUrl), and yet they do. (There's no visible link anywhere in the site, and the displayed list of posts is correct, but nevertheless, the URL works.)

    I AM using a custom BlogProvider. I don't know if that has anything to do with it. I built it from an example provided in another forum post.

    public class BlogProvider : Telerik.Sitefinity.Modules.Blogs.Data.OpenAccessBlogProvider
    {
        public string BlogUrlFormat { get; set; }
        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}]/[UrlName]";
            }
        }
    }
  4. Kristian Smilenov
    Kristian Smilenov avatar
    32 posts
    Registered:
    18 Mar 2015
    20 Jun 2013
    Link to this post
    Hello David,

    I am not able to reproduce this behaviour nor with the default Sitefinity provider or with your custom. When I configure the blog post widget to show only items from specific blog and after that I narrow the selection by selecting a specific category only the post with this category from the blog post are show on the page, and only this link is displayed in the backend under 'Pages where this item can be found'

    I have recorded a video for you to check if I am doing everything like you are. If this is not the case please, 
    record me video and full detailed description of the problem so that i can check it. Additionally you can upload your project to debug it locally.

    Thank you for your cooperation.  

    Regards,
    Kristian Smilenov
    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
4 posts, 0 answered