Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • syn-rg 282 posts 425 karma points
    Oct 24, 2012 @ 09:22
    syn-rg
    0

    Related pages based on keywords in textbox multiple

    I'm building an image gallery, and each image has a set of keywords seperated by a comman in a textbox.

    I want something that allows "related images" to display as a list on the page, using the matched keywords in the textbox.

    Is this possilbe, and if so has anyone got any examples?

    Cheers, JV

  • Ismail Mayat 4511 posts 10092 karma points MVP 2x admin c-trib
    Oct 24, 2012 @ 09:34
    Ismail Mayat
    0

    JV,

    What version of umbraco are you using? Also I take it the keywords are on the media item itself in the media section or are you creating a page then adding to that?

    Regards

    Ismail

  • Fuji Kusaka 2203 posts 4220 karma points
    Oct 24, 2012 @ 11:33
    Fuji Kusaka
    0

    JV,

    Are you trying to display a list of Media Item as you would be doing with nodes? ... i once did something like creating a new mediaType and to this added 2 different upload files one for the image and the other one for attaching a pdf file and textbox to display a summary of the file.

    //fuji

     

  • syn-rg 282 posts 425 karma points
    Oct 25, 2012 @ 00:37
    syn-rg
    0

    Hi Ismail, I'm using Umbraco 4.9. The images are uploaded to the Media section, then using Media Picker to select them for the page in the Content. The keywords are on the content page. Each image has a page created for it.

     

  • Ismail Mayat 4511 posts 10092 karma points MVP 2x admin c-trib
    Oct 29, 2012 @ 10:14
    Ismail Mayat
    0

    Jv,

    You could make use of Examine to do a related search. So for current image get the keywords then do a search to find all content with those keywords and list out the images.

    Regards

    Ismail

  • Chriztian Steinmeier 2800 posts 8790 karma points MVP 8x admin c-trib
    Oct 29, 2012 @ 10:49
    Chriztian Steinmeier
    0

    Hi JV,

    You could try something like this - may need a little tweaking if you're not consistent with whitespace and/or casing in the keywords property:

    <xsl:variablename="siteRoot"select="$currentPage/ancestor-or-self::*[@level = 1]"/>

    <!-- Select all the relevant pages  -->
    <xsl:variablename="galleryPages"select="$siteRoot//DocTypeAlias"/>

    <!-- Create an XPath searchable variable of keywords on the current page -->
    <xsl:variablename="keywordsForPage"select="umbraco.library:Split($currentPage/keywords, ',')"/>

    <!-- Grab all pages that share a keyword with the current page  -->
    <xsl:variablename="relatedPages"select="$galleryPages[umbraco.library:Split(keywords, ',')//value = $keywordsForPage//value)]"/>

    <!-- Sample output... -->
    <xsl:templatematch="/">
           
    <xsl:for-eachselect="$relatedPages">
                   
    <ahref="{umbraco.library:NiceUrl(@id)}">
                           
    <xsl:value-ofselect="@nodeName"/>
                   
    </a>
           
    </xsl:for-each>
    </xsl:template>
    (Change the DocTypeAlias and keywords to your respective alliases)

    /Chriztian

  • Chriztian Steinmeier 2800 posts 8790 karma points MVP 8x admin c-trib
    Oct 29, 2012 @ 12:10
    Chriztian Steinmeier
    1

    The above had a closing </p> instead of a closing </a> -  tried to edit the post but that effed up the formatting - lets try a new one:

    <xsl:variable name="siteRoot" select="$currentPage/ancestor-or-self::*[@level = 1]" />
    
    <!-- Select all the relevant pages  -->
    <xsl:variable name="galleryPages" select="$siteRoot//DocTypeAlias" />
    
    <!-- Create an XPath searchable variable of keywords on the current page -->
    <xsl:variable name="keywordsForPage" select="umbraco.library:Split($currentPage/keywords, ',')" />
    
    <!-- Grab all pages that share a keyword with the current page  -->
    <xsl:variable name="relatedPages" select="$galleryPages[umbraco.library:Split(keywords, ',')//value = $keywordsForPage//value)]" />
    
    <!-- Sample output... -->
    <xsl:template match="/">
            <xsl:for-each select="$relatedPages">
                    <a href="{umbraco.library:NiceUrl(@id)}">
                            <xsl:value-of select="@nodeName" />
                    </a>
            </xsl:for-each>
    </xsl:template>
    

    /Chriztian

     

  • syn-rg 282 posts 425 karma points
    Oct 30, 2012 @ 00:16
    syn-rg
    0

    Thanks Chriztian, that works perfectly!

    I just had to make one change to the following, there was an extra " ) ":

    <xsl:variable name="relatedPages" select="$galleryPages[umbraco.library:Split(keywords, ',')//value = $keywordsForPage//value]" />
  • syn-rg 282 posts 425 karma points
    Oct 30, 2012 @ 01:36
    syn-rg
    0

    Also to omit the current page being displayed in the relatePages results, use the following:

    <xsl:for-each select="$relatedPages[not(self::*[@id = $currentPage/@id])]">

    And to sort them in order of most related "keywords" to least, use the following:

    <xsl:sort select="keywords" order="ascending" />

    Hope this helps someone!
    Cheers, JV 

     

     

     

Please Sign in or register to post replies

Write your reply to:

Draft