我正在尝试在我的主页上显示来自特定类别的文章。
xml 被删除。
注意:我需要从中获取的类别是 id=38。正在显示,但可能是偶然的,因为它包含在当前文章中。
我已经使用我在这里找到的解决方案解决了这个问题。这很简单。我的数据源将类别过滤为 {$ds-categories}。我将其更改为仅 38 并且效果很好。知道这将是一件简单的事情。
我的主页是这样做的,它输出空白 div 代替应该显示的内容:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:import href="../utilities/master.xsl"/>
<xsl:import href="../utilities/get-article.xsl"/>
<xsl:import href="../utilities/pagination.xsl"/>
<xsl:import href="../utilities/get-notes.xsl"/>
<xsl:import href="../utilities/get-comments.xsl"/>
<xsl:template match="data">
<div id="content" class="container">
<div id="content">
<div class="col content">
<div class="col span1">
<h4 class="n4">Recent entries</h4>
</div>
</div>
<xsl:apply-templates select="homepage-articles/entry" mode="short"/>
<xsl:apply-templates select="homepage-updates/entry" mode="updates"/>
</div>
<div id="sidebar" class="col last">
<xsl:call-template name="contact"/>
<xsl:call-template name="social"/>
<xsl:call-template name="category"/>
<xsl:call-template name="tag"/>
<xsl:call-template name="external-links"/>
</div>
</div>
</xsl:template>
</xsl:stylesheet>
然后我的 get-article 模板看起来像这样:
<xsl:template match="entry" mode="updates">
<div>
<xsl:for-each select="entry[@handle = updates]">
<div class="post-meta">
<span><xsl:call-template name="format-date">
<xsl:with-param name="date" select="date"/>
<xsl:with-param name="format" select="'D M'"/>
</xsl:call-template></span>
<span id="year"><xsl:call-template name="format-date">
<xsl:with-param name="date" select="date"/>
<xsl:with-param name="format" select="'Y'"/>
</xsl:call-template></span>
<ul>
<li>
<xsl:text>Tagged as: </xsl:text>
<xsl:for-each select="tags/item">
<a href="{$root}/archive/tag/{@handle}"><xsl:value-of select="."/></a>
<xsl:if test="position() != last()">, </xsl:if>
</xsl:for-each>
</li>
<li><a href="{$root}/post/{title/@handle}#comments"><xsl:value-of select="@comments"/> comment<xsl:if test="@comments != 1">s</xsl:if></a></li>
</ul>
</div>
<div class="post-content last span-7">
<h3><a href="{$root}/post/{title/@handle}"><xsl:value-of select="title"/></a></h3>
<xsl:apply-templates select="body/*[position() < 3]" mode="html"/>
<xsl:call-template name="get-images" />
<p style="float: right; clear: both;"><a href="{$root}/post/{title/@handle}" title="Read {title}">Read the full article</a></p>
</div>
</xsl:for-each>
</div>
</xsl:template>
谢谢您的帮助!一旦我解决了这个问题,它肯定会帮助我避免遇到进一步的问题。