3

I know you can use the Content By Query component to retrieve items under the current site, however, I want to do the opposite.

I'd like to look for items in the parent sites of the current site. I only want to look in parents that are part of the path to the current site (i.e. I don't want to look at siblings and children of the parent sites).

As an extra twist, I want to sort items based on their "distance" from the current site so that I can get the "closest" items.

The idea is to show links to pages that may exist in the parent sites of a page. If there are lots of pages, then give priority to the ones in immediate parents compared to ones further up in the tree structure.

Here's an example:

Home
---\Sport
---\Weather
---\News
---------\National
---------\International
---------------\Europe
---------------\Americas
---------------\Asia
---------------------\China
---------------------\Japan

If I'm at a page in Japan, I'd like to show links to stories in Asia, International, News and Home. I want to display links to Asia stories first, but if there are none, go ahead and look for International Stories. I don't want any National stories or Sports stories.

This is for a public site, so I want to try to use something like CBQ that has been optimized, rather than coding the logic myself and creating a poor performing component. I'm happy to use APIs, as I don't think the out-of-the-box web part is going to cut it.

Any suggestions greatly appreciated

1 Answer 1

1

That might require custom development using Visual Studio. Recently, I built a content query web part (CQWP) that pulls data from the root site and filters and sorts the information. I needed to show the data using a custom look, so I created a custom ItemStyle.xsl file and pointed the CQWP to it. This article describes how to do this.

Here's what I did:

  1. Dropped a CQWP onto a page.
  2. Modified its properties to point to the list at the root level using the Query > "Show items from the following list" option to find the list.
  3. Added a filter to pull information based on the value of a column being "is equal to" a specific value.
  4. Exported the CQWP to file.
  5. Edited the file using a text editor; modified the following property values in the XML file:
    • ItemXslLink: Added my own custom XSL file: <property name="ItemXslLink" type="string">/Style Library/XSL Style Sheets/ItemStyle_ContactDetails.xsl</property>
    • ItemStyle: Pointed to the template name in the XSL file: <property name="ItemStyle" type="string">ContactDetails</property>
    • CommonViewFields: Added my custom columns used in the list that I wanted to read in the XSL file: <property name="CommonViewFields" type="string">MyEmail,Text;MyAddress,Notes;MyDetails,Notes;MyPhone,Notes;MyOpeningHours,Notes;MyEmergencyPhone,Notes;MyMap,Link</property>
  6. In the ItemStyle_ContactDetails.xsl, created my XSLT template to display the columns the way I wanted.

This was done by copying the existing /Style Library/XSL Style Sheets/ItemStyle.xsl file and ripping out the templates already there and creating my own:

<xsl:stylesheet 
  version="1.0" 
  exclude-result-prefixes="x d xsl msxsl cmswrt"
  xmlns:x="http://www.w3.org/2001/XMLSchema" 
  xmlns:d="http://schemas.microsoft.com/sharepoint/dsp" 
  xmlns:cmswrt="http://schemas.microsoft.com/WebParts/v3/Publishing/runtime"
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:msxsl="urn:schemas-microsoft-com:xslt">
  <xsl:output method="xml" indent="yes"/>
  <xsl:param name="ItemsHaveStreams">
    <xsl:value-of select="'False'" />
  </xsl:param>
  <xsl:variable name="OnClickTargetAttribute" select="string('javascript:this.target=&quot;_blank&quot;')" />
  <xsl:variable name="ImageWidth" />
  <xsl:variable name="ImageHeight" />

  <xsl:template name="ContactDetails" match="Row[@Style='ContactDetails']" 
    mode="itemstyle">

     <!-- Render each column the way I want with tables/divs -->

  </xsl:template>
</xsl:stylesheet>

Then I saved the files and uploaded the CQWP to SharePoint as an Imported web part. Loaded it into a page to test. If all went well, uploaded to the CQWP to the web part gallery. You'll have to ensure the XSL file is checked in as well. Ensure the CQWP is imported in after each export; you can't just edit its file directly on the server -- the changes won't display.

For the filtering part, maybe create a custom content type for your different elements, then use the CQWP's Query > "Show items from all sites in this site collection" option. For Content Type, choose your custom content type; this way, you can pull from many different areas of the site.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.