简体   繁体   中英

(Umbraco) How can I list related pages by tags?

In the last node of my site is where the articles are shown, and everyone has its own tags that of course can be the same between some of them, so I wrote a Macro for tags that is working (it lists the tags of the article the user is viewing), I've used the Tag datatype for my 'Article' doctype, and that Macro works correctly; but I got problems with the Macro I wrote to list those articles that have the same tags, I called it RelatedContent.xslt . Here is the code for AllTags.xslt that I found in Umbraco TV Tutorials that works:

<xsl:template match="/">
        <div class="tags">
        <xsl:variable name="Factor" select="6 div Exslt.ExsltMath:max(tags:getAllTagsInGroup('default')/tags/tag/@nodesTagged)"/>
            <xsl:for-each select="tags:getAllTagsInGroup('default')/tags/tag">
                <a class="tag{round($Factor * @nodesTagged)}x" href="?tag={.}">
                    <xsl:value-of select="."/>
                </a><br/>
            </xsl:for-each>
        </div>
</xsl:template>

And the code for RelatedContent.xslt is this:

<xsl:template match="/">

    <ul>
        <xsl:for-each select="$currentPage/node [string(data [@alias='umbracoNaviHide']) != '1'] and (umbraco.library:Request('tag') = '' or contains(data [@alias = 'tags'], umbraco.library:Request('tag')))">
            <li>
                <a href="{umbraco.library:NiceUrl(@id)}">
                    <xsl:value-of select="@nodeName"/>
                    <xsl:value-of select="newsTitle"/>
                </a>
            </li>
        </xsl:for-each>
    </ul>

</xsl:template>

I have not found anything to help me understand this, so I cannot realize how to do it. I will appreciate some help from you. Thanks for your advices.

(Umbraco 6.1.3)

The code for the related content is using the old XML Schema.

Replace this bit:

<xsl:for-each select="$currentPage/node [string(data [@alias='umbracoNaviHide']) != '1']
and (umbraco.library:Request('tag') = '' or contains(data [@alias = 'tags'],
umbraco.library:Request('tag')))">
</xsl:for-each>

With

<xsl:variable name="tag" select="umbraco.library:Request('tag')"/>
<xsl:for-each select="$currentPage/*[@isDoc][umbracoNaviHide != 1][contains($tag,./tag)]">
</xsl:for-each>

The /node element does not exist in the 4.6+ schema, and the element name is replaced with the name of the documentTypeAlias.

So if you have a document type article with a property articleTitle it would be like this:

$currentPage/article/
$currentPage/article/articleTitle

Instead of the old schema (this is incorrect for anything above 4.5)

$currentPage/node[@nodeTypeAlias = 'article']
$currentPage/node[./data[@alias] = 'articleTitle']

You can see the difference between the 2 schemas at the Umbraco wiki:

http://our.umbraco.org/wiki/reference/xslt/45-xml-schema

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM