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

Forums / Developing with Sitefinity / Custom Blog Widget Multiple Blogs

Custom Blog Widget Multiple Blogs

5 posts, 0 answered
  1. Paul
    Paul avatar
    13 posts
    Registered:
    29 Jul 2015
    15 Jan
    Link to this post

    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:

    • Blog One
    1. Post One
    2. Post Two
    3. Post Three

     

    • Blog Two
    1. Post One
    2. Post Two
    3. Post Three

    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

     

  2. Pepi
    Pepi avatar
    981 posts
    Registered:
    28 Oct 2016
    19 Jan
    Link to this post
    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();
    }

    ItemsParentsIds is a property that gets/sets the selected Blogs IDs.
    Manager property represents the current BlogsManager.

    Also, you can find useful information in the following documentation articles:
    Query blog posts
    Widgets

    Note that filtering by blogs is available out of the box in the built-in Blog Posts widget.

    Let us know if you need further assistance.

    Regards,
    Pepi
    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 Sitefinity CMS Ideas&Feedback Portal and vote to affect the priority of the items
     
  3. Paul
    Paul avatar
    13 posts
    Registered:
    29 Jul 2015
    19 Jan in reply to Pepi
    Link to this post

    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?

  4. Pepi
    Pepi avatar
    981 posts
    Registered:
    28 Oct 2016
    19 Jan
    Link to this post
    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
    }

    Then you need to iterate through the Items collection to bind your drop down.You can append “help” to the end of the service URL to see usage instructions (more details for the service signature).

    Another approach is to benefit from Sitefinity Generic Collection binder. You need to apply the following changes in your case:
    1. ServiceUrl="~/Sitefinity/Services/Content/BlogService.svc"
    2. DataMembers="Title, Id"
    3.The <option> will be bound to Title instead of Name:

    <option sys:value="{{Id}}">{{Title}}</option>

    Let us know how it goes.

    Regards,
    Pepi
    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 Sitefinity CMS Ideas&Feedback Portal and vote to affect the priority of the items
     
  5. Paul
    Paul avatar
    13 posts
    Registered:
    29 Jul 2015
    19 Jan
    Link to this post

    Hi Pepi

    Thanks I'll give this a try and see how I get on.

    Regards

    Paul

5 posts, 0 answered