{"id":98,"date":"2008-11-03T11:44:17","date_gmt":"2008-11-03T11:44:17","guid":{"rendered":"http:\/\/www.myfatblog.co.uk\/?p=98"},"modified":"2008-11-03T11:44:17","modified_gmt":"2008-11-03T11:44:17","slug":"content-query-web-parts-the-new-god","status":"publish","type":"post","link":"http:\/\/www.myfatblog.co.uk\/index.php\/2008\/11\/content-query-web-parts-the-new-god\/","title":{"rendered":"Content Query Web Parts.. the new god?"},"content":{"rendered":"<p>I&#8217;ve only worked with the CQWP a few times and have never really got under the bonnet, however just recently at a client they had a requirement that I couldn&#8217;t solve OOTB&#8230; Time to dive into the inner workings of the CQWP.. And boy am I glad i did.. this web part rocks!<\/p>\n<p>There are many good blog posts on how to tailor the content being returned from this web part and how to style the output, so I&#8217;m not going to re-create those here. For those new to CQWP, take a look at Heather Solomons blog post on <a href=\"http:\/\/www.heathersolomon.com\/blog\/articles\/customitemstyle.aspx\">tailoring it to your design<\/a>..<\/p>\n<p>I used that post to deliver two versions of the CQWP on a page. The first showed only the latest story from the news site, with a top left picture and the body of the article page flowing around the image.<\/p>\n<p>The next web part was a roll up of the next 4 stories containing the first 200 characters and a read more link&#8230; Now this is where I hit my problem. I could return the 4 most recent stories, but I already had the most recent on the page, so I didn&#8217;t want to show a summary of that story as well.<\/p>\n<p>To get around this, we need to look further into the XSLT being used to display the results. In order to help you do this, I&#8217;d recommend using the technique shown on <a href=\"http:\/\/frankonmoss.blogspot.com\/2008\/03\/how-to-display-all-fields-available-in.html\">Frank Moss&#8217; blog<\/a> to show all the data being returned by your query.<\/p>\n<p>When you examine the output of this, you&#8217;ll notice that we have several fields to work with. The one that I&#8217;m interested in is &#8220;__beginColumn&#8221; as this appears to only return a True for the first item.<\/p>\n<p>Now i&#8217;m sure that at somepoint, another entry is going to pick up the True again to start a new column, but I&#8217;m only interested in the first four items, so I&#8217;m going to work with this and see if it falls over in the UAT environment..<\/p>\n<p>In your custom XSLT that you&#8217;ve created for your CQWP, we need to wrap the output section for the summary part in an XSL:If statement. but to do this, we need to work with a variable.. So, in the variables section of your chosen style, add the following:-<\/p>\n<pre lang=\"xml\"><\/xsl:variable>\r\n<xsl:variable name=\"columnStart\"><xsl:value-of select=\"@__begincolumn = 'True'\"\/>\r\n<\/xsl:variable>\r\n<\/pre>\n<p>This gives us the value of &#8220;columnStart&#8221; to play with.. So now we wrap the output section of the chosen style in the conditional..<\/p>\n<pre lang=\"xml\">\r\n<xsl:if test=\"$columnStart = 'false'\">     \r\n     <div id=\"linkitem\" class=\"item\" style=\"padding-bottom:2em;\">\r\n       <xsl:if test=\"string-length($SafeImageUrl) != 0\">\r\n     <div > \r\n       <a href=\"{$SafeLinkUrl}\" target=\"{$LinkTarget}\"> \r\n         <img decoding=\"async\" class=\"bs_NewsStyle_Rollup_Image\" src=\"{$SafeImageUrl}\" alt=\"{@ImageUrlAltText}\" \/>\r\n       <\/a>\r\n    <\/div>\r\n<\/xsl:if>\r\n<div class=\"bs_NewsStyle_Rollup_Header\">\r\n    <a href=\"{$SafeLinkUrl}\" target=\"{$LinkTarget}\" title=\"{$DisplayTitle}\">\r\n    <xsl:value-of select=\"$Created\"\/> - <xsl:value-of select=\"$DisplayTitle\"\/>\r\n    <\/a>\r\n    <div class=\"bs_NewsStyle_Rollup\">\r\n       <xsl:value-of select=\"substring($bodyContent, 0, 200)\" disable-output-escaping=\"no\"\/>\r\n       <span class=\"bs_NewsStyle_Rollup_ReadMore\"><a href=\"{$SafeLinkUrl}\" target=\"{$LinkTarget}\" title=\"Read More:\">[Read More...]<\/a><\/span>\r\n    <\/div>\r\n<\/div>\r\n<\/div>\r\n<\/xsl:if>\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>I&#8217;ve only worked with the CQWP a few times and have never really got under the bonnet, however just recently at a client they had a requirement that I couldn&#8217;t solve OOTB&#8230; Time to dive into the inner workings of the CQWP.. And boy am I glad i did.. this web part rocks! There are &hellip; <\/p>\n<p><a class=\"more-link btn\" href=\"http:\/\/www.myfatblog.co.uk\/index.php\/2008\/11\/content-query-web-parts-the-new-god\/\">Continue reading<\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_exactmetrics_skip_tracking":false,"_exactmetrics_sitenote_active":false,"_exactmetrics_sitenote_note":"","_exactmetrics_sitenote_category":0,"footnotes":""},"categories":[25,13,16,24],"tags":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v22.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Content Query Web Parts.. the new god? - Blog of an overweight SharePoint addict<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"http:\/\/www.myfatblog.co.uk\/index.php\/2008\/11\/content-query-web-parts-the-new-god\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Content Query Web Parts.. the new god? - Blog of an overweight SharePoint addict\" \/>\n<meta property=\"og:description\" content=\"I&#8217;ve only worked with the CQWP a few times and have never really got under the bonnet, however just recently at a client they had a requirement that I couldn&#8217;t solve OOTB&#8230; Time to dive into the inner workings of the CQWP.. And boy am I glad i did.. this web part rocks! There are &hellip; Continue reading\" \/>\n<meta property=\"og:url\" content=\"http:\/\/www.myfatblog.co.uk\/index.php\/2008\/11\/content-query-web-parts-the-new-god\/\" \/>\n<meta property=\"og:site_name\" content=\"Blog of an overweight SharePoint addict\" \/>\n<meta property=\"article:published_time\" content=\"2008-11-03T11:44:17+00:00\" \/>\n<meta name=\"author\" content=\"Cimares\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@cimares\" \/>\n<meta name=\"twitter:site\" content=\"@cimares\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Cimares\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"http:\/\/www.myfatblog.co.uk\/index.php\/2008\/11\/content-query-web-parts-the-new-god\/\",\"url\":\"http:\/\/www.myfatblog.co.uk\/index.php\/2008\/11\/content-query-web-parts-the-new-god\/\",\"name\":\"Content Query Web Parts.. the new god? - Blog of an overweight SharePoint addict\",\"isPartOf\":{\"@id\":\"http:\/\/www.myfatblog.co.uk\/#website\"},\"datePublished\":\"2008-11-03T11:44:17+00:00\",\"dateModified\":\"2008-11-03T11:44:17+00:00\",\"author\":{\"@id\":\"http:\/\/www.myfatblog.co.uk\/#\/schema\/person\/55ae8f6885bb5b8390dad001f3da83c6\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"http:\/\/www.myfatblog.co.uk\/index.php\/2008\/11\/content-query-web-parts-the-new-god\/\"]}]},{\"@type\":\"WebSite\",\"@id\":\"http:\/\/www.myfatblog.co.uk\/#website\",\"url\":\"http:\/\/www.myfatblog.co.uk\/\",\"name\":\"Blog of an overweight SharePoint addict\",\"description\":\"The rantings of a (not so) food obsessed IT consultant!\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"http:\/\/www.myfatblog.co.uk\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"http:\/\/www.myfatblog.co.uk\/#\/schema\/person\/55ae8f6885bb5b8390dad001f3da83c6\",\"name\":\"Cimares\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"http:\/\/www.myfatblog.co.uk\/#\/schema\/person\/image\/\",\"url\":\"http:\/\/www.myfatblog.co.uk\/images\/BlogImages\/About_D057\/TopOfTheWorld.jpg\",\"contentUrl\":\"http:\/\/www.myfatblog.co.uk\/images\/BlogImages\/About_D057\/TopOfTheWorld.jpg\",\"caption\":\"Cimares\"},\"sameAs\":[\"http:\/\/www.myfatblog.co.uk\"],\"url\":\"http:\/\/www.myfatblog.co.uk\/index.php\/author\/reginald\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Content Query Web Parts.. the new god? - Blog of an overweight SharePoint addict","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"http:\/\/www.myfatblog.co.uk\/index.php\/2008\/11\/content-query-web-parts-the-new-god\/","og_locale":"en_US","og_type":"article","og_title":"Content Query Web Parts.. the new god? - Blog of an overweight SharePoint addict","og_description":"I&#8217;ve only worked with the CQWP a few times and have never really got under the bonnet, however just recently at a client they had a requirement that I couldn&#8217;t solve OOTB&#8230; Time to dive into the inner workings of the CQWP.. And boy am I glad i did.. this web part rocks! There are &hellip; Continue reading","og_url":"http:\/\/www.myfatblog.co.uk\/index.php\/2008\/11\/content-query-web-parts-the-new-god\/","og_site_name":"Blog of an overweight SharePoint addict","article_published_time":"2008-11-03T11:44:17+00:00","author":"Cimares","twitter_card":"summary_large_image","twitter_creator":"@cimares","twitter_site":"@cimares","twitter_misc":{"Written by":"Cimares","Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"http:\/\/www.myfatblog.co.uk\/index.php\/2008\/11\/content-query-web-parts-the-new-god\/","url":"http:\/\/www.myfatblog.co.uk\/index.php\/2008\/11\/content-query-web-parts-the-new-god\/","name":"Content Query Web Parts.. the new god? - Blog of an overweight SharePoint addict","isPartOf":{"@id":"http:\/\/www.myfatblog.co.uk\/#website"},"datePublished":"2008-11-03T11:44:17+00:00","dateModified":"2008-11-03T11:44:17+00:00","author":{"@id":"http:\/\/www.myfatblog.co.uk\/#\/schema\/person\/55ae8f6885bb5b8390dad001f3da83c6"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["http:\/\/www.myfatblog.co.uk\/index.php\/2008\/11\/content-query-web-parts-the-new-god\/"]}]},{"@type":"WebSite","@id":"http:\/\/www.myfatblog.co.uk\/#website","url":"http:\/\/www.myfatblog.co.uk\/","name":"Blog of an overweight SharePoint addict","description":"The rantings of a (not so) food obsessed IT consultant!","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"http:\/\/www.myfatblog.co.uk\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-US"},{"@type":"Person","@id":"http:\/\/www.myfatblog.co.uk\/#\/schema\/person\/55ae8f6885bb5b8390dad001f3da83c6","name":"Cimares","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"http:\/\/www.myfatblog.co.uk\/#\/schema\/person\/image\/","url":"http:\/\/www.myfatblog.co.uk\/images\/BlogImages\/About_D057\/TopOfTheWorld.jpg","contentUrl":"http:\/\/www.myfatblog.co.uk\/images\/BlogImages\/About_D057\/TopOfTheWorld.jpg","caption":"Cimares"},"sameAs":["http:\/\/www.myfatblog.co.uk"],"url":"http:\/\/www.myfatblog.co.uk\/index.php\/author\/reginald\/"}]}},"_links":{"self":[{"href":"http:\/\/www.myfatblog.co.uk\/index.php\/wp-json\/wp\/v2\/posts\/98"}],"collection":[{"href":"http:\/\/www.myfatblog.co.uk\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.myfatblog.co.uk\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.myfatblog.co.uk\/index.php\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"http:\/\/www.myfatblog.co.uk\/index.php\/wp-json\/wp\/v2\/comments?post=98"}],"version-history":[{"count":0,"href":"http:\/\/www.myfatblog.co.uk\/index.php\/wp-json\/wp\/v2\/posts\/98\/revisions"}],"wp:attachment":[{"href":"http:\/\/www.myfatblog.co.uk\/index.php\/wp-json\/wp\/v2\/media?parent=98"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.myfatblog.co.uk\/index.php\/wp-json\/wp\/v2\/categories?post=98"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.myfatblog.co.uk\/index.php\/wp-json\/wp\/v2\/tags?post=98"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}