lørdag den 14. januar 2012

dk.msn.com News style with Content Query

SharePoint Apps



Coding News web part that resembles News display at dk.msn.com (or uk.msn.com) with one top headline and 5 thumbnail pictures below was not that hard to code.
Here are the things that you have to code:
- display the latest item as headline with large picture
- display as thumbnails, both the latest item and the last 5-6 items below the headline news
- shuffle the items - display item no. 2 as headline and after some time, display item no. 3 and so on
- fade the thumbnail that is currently displayed as headline
- allow user to click or move the mouse over thumbnails and choose which news is displayed as headline
- allow user to click on the item and display the entire item on another page
Here are some tips:
1. Create a custom style in your custom ItemStyle.xsl that is referenced from Content Query web part
2. Create a variable RowNum to display the latest news item as top headline:
3. Write if statement to display only the first item:

..xsl:if test="$RowNum < 1">...

4. Define both a and img tag with id, so you can reference them from JavaScript:

id="newsdisplayimage" src="{$SafeImageUrl}" title="{@ImageUrlAltText}" />

5. Define onClick and onMouseOver for thumbnail image link:

javascript:ShowLarge('')

6. Define thumbnail image with id:



7. Create a reference to JavaScript on the page
8. ShowLarge JavaScript function - example of how to display the thumbnail image as headline - large image:

function ShowLarge(Row) { try {var image=document.getElementById(Row + "_image");var mainimage = document.getElementById("newsdisplayimage");
mainimage.filters.item("DXImageTransform.Microsoft.Fade").apply();
mainimage.src=image.src;
mainimage.filters.item("DXImageTransform.Microsoft.Fade").play();


9. Shuffle between news items:
var t=setInterval("ShowLarge()",12000);


10. Fade thumbnail image for the current headline:
image.style.filter="Alpha(opacity=50)";