Question

I'm doing my first steps with SharePoint and I don't have any idea how to show the number of comments of each entry of a blog in a different page in a upper level.

I guess I have to use a "Content Query Web Part". I edited ItemStyle.xsl adding the fields I want to add, in order to choose the field in the webpart options using the online editor when I edit the page.

I don't know how to continue. What is the next thing I have to do?

Edit

Let me explain the problem again, because I think it wasn't explain correctly.

I have a Site Web with some subsites blog. In order to show the entries in the top site, I set a custom site content type for the entries with the title, etc. fields. With a Content Query Web Part, I choose the BlogEntries and I use my site content type I set. So in the parent site, I can see the entries. It's different for the comments of each entry, because Number of Comment column is not available (I could see this variable on the blog list of entries).

So, the question is, how can I see the number of comment? I thought to add a column into my Site Content Type, but i wasn't able to calculate or search the correct number of comments.

Was it helpful?

Solution

How you can do this using REST API and jquery

Make a GET request to the following URL

/_api/Web/Lists/getbytitle('Comments')/items?$select=Title,PostTitle/Title&$expand=PostTitle

It will give you response like following

{
    "d": {
        "results": [
            {
                "__metadata": {
                    "id": "3d7e5b5c-51fe-4b97-918b-70fb47a44f85",
                    "uri": "YourBlogSiteUrl/_api/Web/Lists(guid'5cd08a1c-e3b0-4aef-bfe2-d58f9dc65e2b')/Items(1)",
                    "etag": "\"1\"",
                    "type": "SP.Data.CommentsListItem"
                },
                "PostTitle": {
                    "__metadata": {
                        "id": "3ba5d89b-048f-41bc-8b7f-b5ecec73a935",
                        "type": "SP.Data.PostsListItem"
                    },
                    "Title": "First post"
                },
                "Title": "sdfsd"
            },
            {
                "__metadata": {
                    "id": "3eba0473-0923-432b-9379-7207b681feae",
                    "uri": "YourBlogSiteUrl/_api/Web/Lists(guid'5cd08a1c-e3b0-4aef-bfe2-d58f9dc65e2b')/Items(2)",
                    "etag": "\"1\"",
                    "type": "SP.Data.CommentsListItem"
                },
                "PostTitle": {
                    "__metadata": {
                        "id": "6e7b3cdc-ec25-41c6-b6c2-6fe4482e2ae3",
                        "type": "SP.Data.PostsListItem"
                    },
                    "Title": "First post"
                },
                "Title": "sdfds"
            }
        ]
    }
}

Now show your comments using jQuery & HTML.

Licensed under: CC-BY-SA with attribution
Not affiliated with sharepoint.stackexchange
scroll top