简体   繁体   English

(Umbraco)如何按标签列出相关页面?

[英](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; 在网站的最后一个节点是显示文章的地方,每个人都有自己的标签,当然其中一些标签可以相同,因此我为有效的标签写了一个宏(列出了文章的标签)用户正在查看),我已经将Tag数据类型用于“ Article”文档类型,并且Macro可以正常工作; but I got problems with the Macro I wrote to list those articles that have the same tags, I called it RelatedContent.xslt . 但是我在编写宏以列出那些具有相同标签的文章时遇到了问题,我将其称为RelatedContent.xslt Here is the code for AllTags.xslt that I found in Umbraco TV Tutorials that works: 这是我在Umbraco电视教程中找到的AllTags.xslt的代码,可以正常工作:

<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: 而RelatedContent.xslt的代码是这样的:

<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) (Umbraco 6.1.3)

The code for the related content is using the old XML Schema. 相关内容的代码使用旧的XML模式。

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. / node元素在4.6+模式中不存在,并且元素名称替换为documentTypeAlias的名称。

So if you have a document type article with a property articleTitle it would be like this: 因此,如果您有一个带有属性articleTitle的文档类型article ,它将是这样的:

$currentPage/article/
$currentPage/article/articleTitle

Instead of the old schema (this is incorrect for anything above 4.5) 而不是旧的架构(这对于4.5以上的版本是不正确的)

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

You can see the difference between the 2 schemas at the Umbraco wiki: 您可以在Umbraco Wiki上看到两种模式之间的区别:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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