BlogPost Full URLs
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();
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:
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.
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]";
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.