Search

Hi,

I'm trying to make filter based on categories.

I have 6 categories:

<categories>
  <section id="27" handle="categories">Categories</section>
  <entry id="89">
    <title handle="articles">Articles</title>
  </entry>
  <entry id="90">
    <title handle="events">Events</title>
  </entry>
  <entry id="91">
    <title handle="books">Books</title>
  </entry>
  <entry id="92">
    <title handle="whitepapers">Whitepapers</title>
  </entry>
  <entry id="93">
    <title handle="movies">Movies</title>
  </entry>
  <entry id="94">
    <title handle="other">Other</title>
  </entry>
</categories>

How to make links to list of entries which have assigned category?

Thanks

<xsl:for-each select="/data/categories/entry">
   <xsl:variable name="category" select="."/>

   <xsl:value-of select="$category/title"/>

   <ul>
      <xsl:for-each select="/data/entries-by-category/entry[ category/item/@id = $category/@id ]">
         <li>
            <xsl:value-of select="title"/>
         </li>
      </xsl:for-each>
   >/ul>
</xsl:for-each>

I want to do something like this:

<xsl:template match="posts-filter/entry">
  <li><a href="#"><xsl:value-of select="title"/></a></li>
</xsl:template>

<ul>
  <xsl:apply-templates select="/data/posts-filter/entry"/>            
</ul>

but, what to enter in href="" ?

Assuming you want to recall the category name (or part of it) in each link, the href would be something like this:

<xsl:template match="data">
    <ul>
        <xsl:apply-templates select="posts-filter/entry"/>
    </ul>
</xsl:template>

<xsl:template match="posts-filter/entry">
    <li>
        <a href="#{title/@handle}"><xsl:value-of select="title"/></a>
    </li>
</xsl:template>

We have 6 categories (links) on main page:

Articles | Events | Books | Whitepapers | Movies | Other

On the main page I have all entries that have these categories, but when I clikc 'Events' I should get all entries with 'Events' category.

Mmm, so, you’re planning to have all articles displayed in the Home page and allow a user to filter them by means of a menu which links correspond to the different categories.

Assuming you have:

  • two sections named Categories and Articles, where Articles has, among the others, a Select Box Link field named Category pointing to the Text Input field named Title of the section Categories;
  • two data sources named Categories and Articles, each of them fetching entries from the corresponding section of the same name and attached to a both an index page named Home and a page named Articles;
  • the page Articles having a URL Parameters named category;
  • the data source Articles having a data source filter which value is {$category}.

Given such premises, your XSLT should be something similar to:

<xsl:template match="data">
    <xsl:apply-templates select="categories"/> <!-- to list the categories -->
    <xsl:apply-templates select="articles"/> <!-- to list the articles -->
</xsl:template>

<xsl:template match="categories">
    <ul>
        <xsl:apply-templates select="entry"/>
    </ul>
</xsl:template>

<xsl:template match="categories/entry">
    <li>
        <a href="{$root}/articles/{title/@handle}"><xsl:value-of select="title"/></a>
    </li>
</xsl:template>

<xsl:template match="articles">
    <section>
        <h2>Articles</h2>
        <xsl:apply-templates select="entry"/>
    </section>
</xsl:template>

<xsl:template match="articles/entry">
    <div>
        <!-- this article title, date, etc. -->
    </div>
</xsl:template>

I didn’t test the code, but if your premises are like the above ones, it should work.

On the main page (blog.xsl) I have:

<xsl:template match="posts-filter/entry">
  <li><a href="{$blog}"><xsl:value-of select="title"/></a></li>
</xsl:template>

And this is my inported utility:

<div class="blog-filter">
  <ul>
    <li><strong>Filter/limit posts to:</strong></li>
    <xsl:apply-templates select="/data/posts-filter/entry"/>
  </ul>
</div>

In Symphony I have DS named Posts Filter and Source set to Categories.

I have 2 sections: Articles and Categories. In Articles I have field Select Box Link linked to Categories.

The thing is that I'd like to make links to only these entries that have particular categories and display on main page.

What is the best way to do this?

OK, I think I made it using search_index extension.

<xsl:template match="posts-filter/entry">
  <li><a href="{$blog}/?keywords={title/@handle}"><xsl:value-of select="title"/></a></li>
</xsl:template>

Mmm, I think you should be able to make it also without having to install the Search Index extension by writing in your XSTL template:

<xsl:template match="posts-filter/entry">
    <li><a href="{$root}/?category={title/@handle}"><xsl:value-of select="title"/></a></li>
</xsl:template>

if clicked, the link will return you a new param named url-category in the param pool, which you can add as a filter — {$url-category} — to the Select Box Link field in your data source Articles.

Create an account or sign in to comment.

Symphony • Open Source XSLT CMS

Server Requirements

  • PHP 5.3-5.6 or 7.0-7.3
  • PHP's LibXML module, with the XSLT extension enabled (--with-xsl)
  • MySQL 5.5 or above
  • An Apache or Litespeed webserver
  • Apache's mod_rewrite module or equivalent

Compatible Hosts

Sign in

Login details