Sign In  
Liam Cleary [SharePoint MVP]
RSS Feed Feed : Posts
hit counters
Add to Google Reader or Homepage
Subscribe in NewsGator Online
Add Liam Cleary [MVP SharePoint] to Newsburst from CNET News.com
Subscribe in Bloglines
Blog : Interesting Links
  Shareworkz
  BDC MetaMan
  Bamboo Solutions
  Corasworks
  Where I Work
  CKS
 
Blog : Links
  My Facebook Profile
  My Linkedin Profile
  My Xing Profile
  Downloads
  MVP Profile
  Technorati Profile
  Contact Me
  Code Library
  Twitter
 
Blog : Categories
  All Me!! Baby!!
  CKS
  CQWP
  Development
  Email
  Family
  General
  Groove
  InfoPath
  IRM
  Longhorn
  Lotus Notes
  Migration
  Mobility
  Office System 2007
  Personal Projects
  Records Management
  Security
  SharePoint
  Silverlight
  Testing
  Vista
  VSTO
  WSS
  XSL
 
Blog : Archives
  June 2007 (4)
  May 2007 (7)
  July 2007 (20)
  January 2007 (4)
  September 2006 (5)
  August 2006 (3)
  February 2007 (3)
  March 2007 (1)
  August 2007 (6)
  September 2007 (7)
  October 2007 (6)
  November 2007 (9)
  December 2007 (5)
  January 2008 (12)
  February 2008 (5)
  March 2008 (4)
  April 2008 (5)
  May 2008 (10)
  June 2008 (6)
  July 2008 (3)
 
Blog : Favorites
  Mark Bower
  Nigel Bridport
  Mark Deakin
  Jessica Gruber
  Martin Kearn
  SharePoint Team
  InfoPath Team
  Office Zealot
  OfficeRocker
  Todd Bleeker
  Mark Harrision
  Bill English
  Erol
  Julie Kremer
  Kathleen McGrath
  Joe Friend
  Mike Fitzmaurice
  JOPX
  Jensen Harris
  PJ Hough
  mszCool's
  Todd Baginski's
  MS Records Mngmt
  Amanda Murphy
  Shane Perran
  Darren Strange
  Jason Medero
  Bob Fox
  Tobias Zimmergren
  Eli Robillard
  Joel Oleson
  Tom Rizzo
  Dustin Miller
  Ted Pattison
  Bob Mixon
  Andrew Connell
  Keith Richie
  Pattrick Tisseghem
  Shane Young
  Arpan Shah
  Heather Solomon
  Steven Van de Craen
  MS Knowledge Network
  ECM Team Blog
  Ivan Wilson
  Nick Swan
  Ishai Sagi
  Andrew Woodward
  Ben Robb
 
CKS
 
[06/11/2007] MOSS2007 – Link Lists and the Content Query Web part
 
Categories: Development, Office System 2007, SharePoint
 

As most of you have probably found when you use link lists within SharePoint and then try to consume them within a CQWP, they do not display correctly. Normally when you try to consume a list or library within a CQWP the "Title" field is rendered by default. However a link list within SharePoint does not have a title field as this is a hidden field.

When you add the web part is renders as shown below:

If there was a title field this would then show the value and link direct to the item itself. To correct this issue we need to create a custom style within the "ItemStyle.xsl" file. For ease and convenience simply copy the default one and rename as appropriate. In this demo we will simply call it "DemoLinks". The XSL code before the changes looks as shown below:

The changes we will make are to strip out the majority of the code and then some XSL functions to strip out the correct values. When using the URL field from the "Links" list, the value it returns contains not only the URL value but also the description you types in. The format is:

http://www.helloitsliam.com, My Blog Site

If we just tell the XSL to simply render the URL field it will render in the format as shown above. Instead we use the "substring-after" and "substring-before" functions to slice up the value above into chunks and then render the parts we need. The CQWP by default will generate the link for the item but it won't actually be to the URL link you filled in, but to the exact list item for that entry. In the new code block shown below we remove all of the variables created by default for such things as "$SafeLinkURL". We simply replace the hyperlink code with the value we needed after chopping up the value using the substring functions. The completed code looks like this:

Notice in the following the code block the substring functions and where we use the comma as the separator to chop the value into the parts we need.

Now once we apply this style to our web part, it should render as shown below:

Notice that when you hover over the item the URL link is to the actual URL not the list item URL. This was achieved with the code above by using the "substring-before" function which as it is called takes everything before the separator that you specify, the "substring-after" works the other way around.

As a side not in order for this to work you must first tell the CQWP to render the URL field or custom field you are using. This is done by exporting the web part down and modifying the "CommonViewFields" value to something like below:

You will then need to upload this web part and then apply the style as shown above.

NOTE: Make sure you check the customised "ItemStyle.xsl" in or it may not render at all.

 
 Delicious    Digg    reddit    Facebook    StumbleUpon  
1 Comment
 

Comments

Friday, 30 Nov 2007 10:38 by Jaap Steinvoorte
Hi Liam, Thanks for this post. I'm currently developing a new portal with several blogs. I want to display recent comments of these blogs on the main page of this portal. I tried for a week to display this but I can't find a solution. First issue I have is a URL I do not want (http://community.ada-ict.nl/blogs/virtualgenerations/Lists/Comments/3_.000) Second one is that the PostTitle (lookup) is empty. I used P: V: for displaying the queried fields(PostTitle, CommentUrl, author, Created and Body). I modified the commonviewfields, I inserted the servertemplateID (302 for the commentslist). I checked schema.xml if I used the correct names for the fields. Third one: body is empty. This one is totally odd in my opinion... I'm getting a little desperate. Do you have any suggestions, tips or ideas? (btw, I use CKS:EBE which has some extra colums Jaap

Name:
URL:
Email:
Comments:
CAPTCHA Image Validation