# Featured listings strip

Source: https://help.ruuster.com/idx/recipe-featured-strip

> A strip of eight featured homes for your homepage, from a collection you curate in Ruuster or from your own listings, rendered on your server.

A strip of eight homes for your homepage. It shows a collection curated in the Ruuster Platform
(hand-picked listings or a stored search), or, when you have none, your brokerage's own listings. A
Listings API account that is not on the Platform has no collections, so it shows your own listings. It is rendered on
your server with links to each listing page, and it leaves itself out when there is nothing to show.

## What the visitor sees

<figure class="idx-shot"><img src="/idx-docs/screens/ours/featured-strip-1440.png" alt="Featured homes strip for a homepage, on a desktop (1440 px wide)" width="1440" height="900" loading="lazy" decoding="async"><figcaption>The strip of featured homes.</figcaption></figure>

<figure class="idx-shot"><img src="/idx-docs/screens/ours/featured-strip-375.png" alt="Featured homes strip for a homepage, on a phone (375 px wide)" width="375" height="1470" loading="lazy" decoding="async"><figcaption>The strip of featured homes.</figcaption></figure>

The markup is `static/html/featured-strip.html` in `@ruuster/idx-recipes`. The [HTML and CSS recipe](https://help.ruuster.com/idx/recipe-html-css) shows how to fill it and which stylesheet and script to load.

## What the page calls

| When | Request | Key | Cached |
|---|---|---|---|
| Each homepage render, with a collection | `GET /v1/collections/{collectionId}/listings?limit=8` | secret key, on your server | 5 minutes by Next.js |
| Each homepage render, without one | `GET /v1/listings?ownListings=1&limit=8` | secret key, on your server | 5 minutes by Next.js |

cURL:

```bash
curl -s -G "https://idx.ruuster.com/v1/collections/emb_fixture_picks/listings" \
  --data-urlencode limit=8 \
  -H "Authorization: Bearer $IDX_SECRET_KEY"
```

TypeScript:

```typescript
import { createClient } from "@ruuster/idx";

const idx = createClient({ secretKey: process.env.IDX_SECRET_KEY });

const r = await idx.collectionListings("emb_fixture_picks", {
  limit: 8,
});
if (!r.ok) throw new Error(`${r.error.code}: ${r.error.message}`);
console.log(r.data);
```

Python:

```python
import os

import requests

res = requests.get(
    "https://idx.ruuster.com/v1/collections/emb_fixture_picks/listings",
    params={
        "limit": "8",
    },
    headers={"Authorization": "Bearer " + os.environ["IDX_SECRET_KEY"]},
    timeout=30,
)
body = res.json()
if not body["ok"]:
    raise RuntimeError(body["error"]["code"] + ": " + body["error"]["message"])
print(body["data"])
```

PHP:

```php
<?php

$query = http_build_query([
    'limit' => '8',
], '', '&', PHP_QUERY_RFC3986);
$ch = curl_init('https://idx.ruuster.com/v1/collections/emb_fixture_picks/listings' . '?' . $query);
curl_setopt_array($ch, [
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_HTTPHEADER => ['Authorization: Bearer ' . getenv('IDX_SECRET_KEY')],
    CURLOPT_TIMEOUT => 30,
]);
$body = json_decode(curl_exec($ch), true);
curl_close($ch);
if (!$body['ok']) {
    throw new RuntimeException($body['error']['code'] . ': ' . $body['error']['message']);
}
print_r($body['data']);
```

cURL:

```bash
curl -s "https://idx.ruuster.com/v1/collections" \
  -H "Authorization: Bearer $IDX_SECRET_KEY"
```

TypeScript:

```typescript
import { createClient } from "@ruuster/idx";

const idx = createClient({ secretKey: process.env.IDX_SECRET_KEY });

const r = await idx.request("/collections");
if (!r.ok) throw new Error(`${r.error.code}: ${r.error.message}`);
console.log(r.data);
```

Python:

```python
import os

import requests

res = requests.get(
    "https://idx.ruuster.com/v1/collections",
    headers={"Authorization": "Bearer " + os.environ["IDX_SECRET_KEY"]},
    timeout=30,
)
body = res.json()
if not body["ok"]:
    raise RuntimeError(body["error"]["code"] + ": " + body["error"]["message"])
print(body["data"])
```

PHP:

```php
<?php

$ch = curl_init('https://idx.ruuster.com/v1/collections');
curl_setopt_array($ch, [
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_HTTPHEADER => ['Authorization: Bearer ' . getenv('IDX_SECRET_KEY')],
    CURLOPT_TIMEOUT => 30,
]);
$body = json_decode(curl_exec($ch), true);
curl_close($ch);
if (!$body['ok']) {
    throw new RuntimeException($body['error']['code'] . ': ' . $body['error']['message']);
}
print_r($body['data']);
```

`GET /v1/collections` lists your collections and their ids.

## Steps

1. Add `lib/idx.ts` and `lib/site.ts` from the [recipes overview](https://help.ruuster.com/idx/recipes).
2. To show a collection, put its id in `FEATURED_COLLECTION_ID` in `lib/site.ts`. Leave it `null` to
   show your own listings.
3. Create `components/featured-strip.tsx` with the code below and add `<FeaturedStrip />` to your
   homepage ([Homepage search bar](https://help.ruuster.com/idx/recipe-search-bar) has the page).
4. Open `http://localhost:3000`.

## The code

<p class="code-title"><code>components/featured-strip.tsx</code></p>

```tsx
// Eight featured homes for the homepage: a collection you curate in Ruuster, or your own listings.
import { ListingGrid, MlsDisclaimers } from "@ruuster/idx-recipes";
import { idx } from "@/lib/idx";
import { FEATURED_COLLECTION_ID } from "@/lib/site";

export async function FeaturedStrip({ title = "Featured homes" }: { title?: string }) {
  const r = FEATURED_COLLECTION_ID
    ? await idx.collectionListings(FEATURED_COLLECTION_ID, { limit: 8 })
    : await idx.search({ ownListings: true, limit: 8 });
  // The strip is optional: when there is nothing to show, the homepage simply leaves it out.
  if (!r.ok || r.data.listings.length === 0) return null;
  return (
    <section aria-labelledby="featured-homes">
      <h2 id="featured-homes">{title}</h2>
      <ListingGrid listings={r.data.listings} mls={r.meta.mls} ga4ListName={title} />
      <MlsDisclaimers mls={r.meta.mls} asOf={r.meta.freshness.asOf} />
    </section>
  );
}
```

## Forms and your CRM

The strip carries no form. Each card leads to its listing page, where your tour form is
([Registration, tour and contact forms](https://help.ruuster.com/idx/recipe-forms)).

## Rules this page follows

**MUST**

- Show each card's attribution line where its board requires one, and the disclaimers under the strip.
- Link each card to your own listing page.

**NEVER**

- Show a home in the strip that the API did not answer.

## Test it

```sh
curl -s http://localhost:3000/ | grep -o 'href="[^"]*/homes/[^"]*"' | sort -u | wc -l
```

The count includes the strip's eight cards. View source and find the disclaimer under the strip.

## Build it with AI

Use the homepage prompt and add one sentence: "Add a featured strip of eight homes from my collection,
or from my own listings when I have none, using the featured strip recipe."

```text
Read RUUSTER_IDX.md first and follow its MUST and NEVER rules. Ask me if it doesn't cover something.

Add a search bar to the homepage of my site that hands off to my search page, following <https://help.ruuster.com/idx/recipe-search-bar>. Use the SearchBox component with baseUrl="/api/idx" and action="/search", and add the route app/api/idx/[...path]/route.ts with `export const GET = createListingsRoute({ basePath: "/api/idx" });` if it is not there yet. It suggests places after three characters, and picking one goes to /search with the place's where object in the URL. The search page renders that search on the server with my secret key.

Use this environment variable: IDX_SECRET_KEY (server only). Never paste a secret key into a chat. No key goes in any page: my pages call my own /api/idx route, made with createListingsRoute from @ruuster/idx/route, which adds my secret key on the server (on a site with no server, the widgets call the API with no key from my approved website address).

When you are done, tell me how to test it with the keyboard only.
```

On a site without React, such as PHP, Python, Ruby on Rails, Go or plain HTML, [Build without React: HTML, CSS and JavaScript](https://help.ruuster.com/idx/recipe-html-css) gives you the same markup, the stylesheet and the script for every widget.
