Tuesday, September 14, 2010

Show Incoming Links on a Wiki Page - for SharePoint 2010

For those of you who saw my post on how to add the incoming links to a wiki page for 2007, it linked to a page that described how to add a bit of code to a CEWP and have the pages that linked to the wiki page display on the page itself. This prevented you from having to browse to a different page to see this information.

The last time I looked, there was no update for SharePoint 2010, and I desperately needed it for a project I was working on. I was lucky enough to get my hands on a SharePoint Developer who was able to hack it out for me. He took the liberty of changing the reference to the Google jQuery Library to Microsofts Library.

He also added a few things like spacing the text from the left of the page, and the ability to change the font size. Hope this helps - it works like a charm for my project!

<script src="http://ajax.microsoft.com/ajax/jquery/jquery-1.4.2.min.js" type="text/javascript"></script>
<script type="text/javascript">
$(function() {

function addLinks(){

//get the url for the incoming links page
var starturl = SP.Utilities.Utility.getLayoutsPageUrl('BackLinks.aspx');

var builder = new SP.Utilities.UrlBuilder(starturl);
builder.addKeyValueQueryString('List', (new SP.Guid(_spPageContextInfo.pageListId)).toString());
builder.addKeyValueQueryString('ID', _spPageContextInfo.pageItemId.toString());
var u = builder.get_url();

//create a target container and load it with the incoming links
//filtered to show the links list only

var l = $("<div id='incomingLinks' style='border-top: solid 1px silver'>").load(u + " #MSO_ContentTable .ms-bodyareacell", function(){

l.css("font-size", "11pt").find("a").css("padding-left", "11px").css("font-size", "11pt");
});

//append the new container to the wiki content


$(".ms-wikicontent").append(l);


}
ExecuteOrDelayUntilScriptLoaded(addLinks, "sp.js");


});


</script>

1 comment: