Custom Blog Widget Multiple Blogs
Hi,
I am developing a custom blog widget to understand more about how sitefinity works, as I feel that in order to utilize sitefinity more I must get an understanding of how it works instead of using out of the box functionality.
I currently have a blog widget that has a master / detail setup all going great.
What I would like to achieve now is to be able to filter these by the specific blog they are in i.e:
What I would like to do is only show the posts for blog one or blog two.
I would guess that I can get a list of the blogs from the blog manager and they bind these to a dropdown in the designer so that the user can choose?
Would anybody know how this can be achieved and if so share a little code to explain?
Thanks
Paul
Hello Paul,
Here is how the required functionality is implemented in Sitefinity:
IQueryable<BlogPost> query;var blogIds = this.ItemsParentsIds.ToArray();if (blogIds != null && blogIds.Length > 0) query = this.Manager.GetBlogPosts().Where(post => blogIds.Contains(post.Parent.Id));else query = this.Manager.GetBlogPosts();Hi Pepi
Thanks for the info, I think maybe I wasn't clear in what I was trying to achieve. I was trying to populate a dropdown list in a widget designer so that the user can select which blog they want.
I have had a look into the widget designer and I am guessing I can use javascript / jquery to call a service that will return me the blogs?
Is this correct?
Hello,
Yes, you can use JQuery to call ~/Sitefinity/Services/Content/BlogService.svc that will return all blogs in JSON format:
"Context": null, "IsGeneric": false, "Items": [ "AdditionalStatus": null, "Author": "admin admin", "AvailableLanguages": [""], "CommentsCount": 0, "DateCreated": "\/Date(1452673639530)\/", "DateModified": "\/Date(1452673639530)\/", "DefaultPageId": null, "ExpirationDate": "\/Date(-62135596800000)\/", "Id": "d5e3212e-c0d7-6231-8246-ff0000135377", "IsDeletable": true, "IsEditable": true, "ItemsCount": 0, "LastApprovalTrackingRecord": null, "LifecycleStatus": "ErrorMessage": null, "HasLiveVersion": false, "IsAdmin": true, "IsLocked": false, "IsLockedByMe": false, "IsPublished": false, "LastModified": null, "LastModifiedBy": null, "LockedByUsername": null, "LockedSince": null, "Message": "Published", "PublicationDate": null, "SupportsContentLifecycle": false, "WorkflowStatus": "Draft" , "LiveContentId": "d5e3212e-c0d7-6231-8246-ff0000135377", "Owner": "admin admin", "ParentUrl": null, "ProviderName": "OpenAccessDataProvider", "PublicationDate": "\/Date(1452673630937)\/", "Status": "Draft", "Title": "blog1", "UIStatus": "Draft", "Version": 0, "VersionInfo": null, "WorkflowOperations": null, "Url": "\/blog1", "LastPostDate": "\/Date(1452673663000)\/", "PostCount": 1 ], "TotalCount": 1<option sys:value="Id">Title</option>Hi Pepi
Thanks I'll give this a try and see how I get on.
Regards
Paul