# Category listings

Code examples for category listings.

**Facets, Filtering and Sorting**

Facets can be applied to category listings in a similar way to search. Have a look at the [facets guide](/infinity/developer-guide/faceting.md#when-can-facets-be-applied) for more details.

Custom filtering and sorting options are also available for category listings. Have a look at the [sorting and filtering guide](/infinity/developer-guide/sorting-and-filtering.md) for more details.

**Example**

The example shows how to list products in a category. The call is structured much like a search call and the parameters work in the same way so have a look at the explanation of [search parameters](/infinity/developer-guide/infinity-search.md#search-parameter-introduction) if you’re unsure how they work.

Other than that, listing categories is simply a matter of calling `GetEntitiesByAttribute` and supplying the name of the category that you want to list.

{% tabs %}
{% tab title="C#" %}

```csharp
// Below is an example of a request - response cycle of a category listing request
var request = new GetEntitiesByAttributeRequest("Category", categoryName);
request.ResultsOptions.Skip = 0;
request.ResultsOptions.Take = 9;

var response = _loop54Client.GetEntitiesByAttribute(request);

var results = response.Results.Items;

if (!results.Any())
    Debug.WriteLine("There were no items in this category.");

foreach (var resultItem in results)
{
    var productId = resultItem.GetAttributeValueOrDefault<string>("Id");
    var productTitle = resultItem.GetAttributeValueOrDefault<string>("Title");
    Debug.WriteLine(productId + " " + productTitle);
    //render a product on the category listing page
}
```

C# source code on Github: [CategoryListingController.cs](https://github.com/LoopFiftyFour/.NET-Connector/blob/master/Loop54.NetCoreCodeExamples/Controllers/CategoryListingController.cs)
{% endtab %}

{% tab title="Java" %}

```java
// Below is an example of a request - response cycle of a category listing request

GetEntitiesByAttributeRequest request = new GetEntitiesByAttributeRequest("Category", categoryName);
request.resultsOptions.skip = 0;
request.resultsOptions.take = 9;

GetEntitiesByAttributeResponse response = loop54Client.getEntitiesByAttribute(request);
List<Entity> results = response.results.items;

if (response.results.count == 0)
  System.out.println("There were no items in this category.");

for(Entity resultItem : results)
{
  String productId = resultItem.id;

  String productTitle = resultItem.getAttributeValueOrNull("title", String.class);
  System.out.println(productId + " " + productTitle);
  //render a product on the category listing page
}
```

Java source code on Github: [CategoryListingController.java](https://github.com/LoopFiftyFour/Java-Connector/blob/master/codeexamples/src/main/java/com/loop54/spring/test/codeexamples/web/CategoryListingController.java)
{% endtab %}

{% tab title="JavaScript" %}

```javascript
// Below is an example of a request - response cycle of a category listing request
var response = client
  .getEntitiesByAttribute("Category", categoryName, { skip: 0, take: 9 })
  .then(r => {
    var data = r.data
    var results = data["results"].items

    if (!results || results.length == 0) {
      console.log("There were no items in this category.")
    } else {
      console.log("Total number of items: " + data["results"].count)
      for (var i in results) {
        var productId = results[i].id
        var productTitle = results[i].attributes
          ? results[i].attributes.find(function (a) {
              return a.name == "Title"
            }).values[0]
          : ""
        console.log(productId + " " + productTitle) //render a product on the category listing page
      }
    }
  })
```

JavaScript source code on Github: [categorylisting.js](https://github.com/LoopFiftyFour/JS-Connector/blob/master/codeexamples/categorylisting.js)
{% endtab %}

{% tab title="PHP" %}

```php
/* Configure a request to get the 9 first items in the Meat category */
$request = $connector->getEntitiesByAttribute('Category', 'Meat');
$request->resultsOptions()
->skip(0)
->take(9);

/* Actually perform the request */
$response = $connector->query($request);

/* Print all results in this response. */
echo 'Items in category:' . PHP_EOL;
foreach ($response->getResults() as $entity) {
$id = $entity->getId();
$title = $entity->getAttribute('Title');
echo $id . ': ' . $title . PHP_EOL;
}
```

PHP source code on Github: [Simple.php](https://github.com/LoopFiftyFour/PHP-Connector/blob/master/examples/Simple.php)
{% endtab %}
{% endtabs %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.fact-finder.com/infinity/developer-guide/category-listings.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
