Azure / Office 365 / SharePoint Development / Search

Take your SharePoint social features to the next level with “I like it” and “Tags” counters: Part 4

April 11, 2012

My intention was to write three blog posts on this topic, but a commenter told me that a problem arises with blog post items. The counters always return zero.

In this part I will show you why this is happening and what you could do to solve this.

Blog with social features

Blog with social features

First of all the reason why it is happening.

Reason

A standard blog post URL in SharePoint looks like this: http://sp2010/Lists/Posts/Post.aspx?ID=1.

Using this URL on the Manage Social Tags and Notes page of my user profile service, it did not return any results.

Posts Query

Posts Query

Normally it should return the following items:

Blog post tags

Blog post tags

When I did a query for all the tags from a specific user, I noticed something interesting:

ViewPost Reference

ViewPost Reference

The tags are not linked to the Post.aspx page, but to the ViewPost.aspx page: http://sp2010/Lists/Posts/ViewPost.aspx?ID=1.

When I checked the URL of the Social Data Frame, I saw that it also used the ViewPost.aspx page as reference.

Solution

The solution is very simple, you only need to replace the Post.aspx from the URL path with ViewPost.aspx.

Here is the code to do this:

Here you can find the whole code:

SocialFeatures Code

Result

Blog post tags end result

Blog post tags end result

Comments

  • Awesome article! Helped me a lot. I am wondering if you have an idea about how to change the “Tag & Notes” button to open up the Note board tab in the popup by default, rather than the Tags tab, so it can be used to comment on list items. Thanks

    • estruyf

      Grimmjow,

      Thank you. That is possible, and it isn’t that much work to achieve it. When you click on the “Tag & Notes” button, the following page opens: Your-Site/_layouts/socialdataframe.aspx?Url=”Your-Page”&Title=”Your-Title”&mode=0&IsDlg=1.
      The Mode option will be used to set the opening page, 0: Open Tag & Notes – 1: Note Board.

      So what we need to do is change the function parameters behind the Tags & Notes button (by default: TagDialogOpener.Open(‘Your-Page’, document.title, ‘0’);). ‘0’ needs to be changed to ‘1’. To do this you can add the following jQuery script to your JavaScript file or master page. Be sure you have referenced jQuery.

      $(function() {
      var elm = $(‘#TagsAndNotes_ctl00_ctl36’);
      var attr = elm.attr(‘onclick’);
      attr = attr.replace(“‘0’);”, “‘1’);”)
      elm.attr(‘onclick’, attr);
      });

  • Thanks a lot E. I have made custom buttons for like & notes so making this change should be straight forward. There is something very weird about how the custom buttons are behaving though. I have multiple like buttons on a page so as a test I have made a content editor web part with the following script. It basically has two links that like two different pages in the site. The problem is that when i click on the two links one after the other, only the link that gets clicked first registers the like. I verify this by the using the default ‘Tag and Notes’ button on the 2 pages which display ‘i like it’ if the like has been registered. After clicking both the like buttons, i get the message “Add Tag..” which does verify that the script was executed but somehow the button that was clicked 2nd did not register the like.

  • That’s just a simplified example. In actuality, it is a custom announcements web part where the user can like or comment on an announcement. We can have multiple announcements so essentially multiple like buttons on the same page to like list items. Thanks

    • estruyf

      Ok, now I understand your question why you want to do this. I tested it and updated your code a bit: http://pastebin.com/zQUh1KTi

      When I click on “Link 1” and then “Link 2”, they are correctly submitted (check this video: http://screenr.com/Ogj8).

      Regards,
      EStruyf

  • Thanks for those responses estruyf. I appreciate it. The code change you did does not seem to have solved the problem however. You have combined both the javascript functions into one and passed a string into tagged_text. In the video, you click on both the buttons and they show the given notification message. If you actually go to both those URLs which were liked and click the out of box the ‘Tag & Notes’ button, they should show ‘i like it’ as a registered tag but it only shows up for the 1st page that was liked. This is the problem here, it looks like the “like” script executed successfully but if you use the “Tag & Notes” button, it does not show the like tag for the 2nd page. Even in the Central Admin -> Manage Social Tag and Notes, the registered like does not show up for the 2nd page.

    http://i47.tinypic.com/27zwuxj.png

    • estruyf

      Grimmjow,

      I gave it another title to show that the two are registered. If I check it in Central Administration, my click is registered for both the clicks (tested this on other pages). What you can do is try to put a sleep event (2 seconds or so) before submitting the quick tags.

      Regards,
      EStruyf

  • khadar

    Please can you help me how to take hit count of email post links in 2010 blog site.