Welcome to Genhike Sports

Content List

← Back to the tag reference

Hand-written Includes in-depth notes

Content List content_list Used inside components 52 host files / 69 calls

Fetches a list of content items for one model. This is the most used tag: news, product, and case lists all rely on it.

content_list(array $options = [])

Pages Home List pages Detail pages Single pages

Used in
Home / List pages / Detail pages / Single pages
Defined in
core/tpl_functions.php:157
Core method
Tpl::contentList()
How do I read these repository paths?

All paths are relative to the site root. Open core/tpl_functions.php at line 157 to see the definition of content_list(). The "core method" is what the tag actually forwards to: a template writes content_list(...) and the core runs Tpl::contentList(...).

1. Fill in parameters, get the code Edit any field and the result below updates instantly; press Copy and paste it into a template. It also works without JavaScript: press Generate and the server recomputes it.

click the title to collapse / expand
Model code, defaults to news; an unknown code returns an empty array.
Category ids, or an array; omit for all. A slug becomes 0 and returns no rows.
Fetch by category slug (for example news); use either this or category, the core resolves it to an id first.
Subcategories are excluded by default; only an explicit true includes them.
Rows to fetch. Omitting it fetches every row: there is no default and no cap.
e.g. views desc; unknown fields are dropped and the default order applies.
Flag filter: top / recommend / hot; other values are ignored.
Keyword: split on spaces and punctuation, terms are ANDed across searchable fields.
Ids to exclude; several ids need an array such as [3, 5], while the comma string '3,5' uses only the first id. The generator in the tag tool turns an input of 3,5 into [3, 5] for you.
Language code, defaults to the current one; all returns all languages mixed.
Generated code

Now generating: content_list

Real page previewOpen in new window

This is the real rendering of the page (real header, container, this tag output, real footer). It reloads when you change a parameter.

This is the server-computed default; it updates as you edit any parameter and the preview on the right is re-rendered too. It also works without JavaScript: fill the form and press Generate.

2. Full parameter table 10 parameters, one per row; scroll sideways on narrow screens.

click the title to collapse / expand
Parameter Type Default Description
model string news Model code, defaults to news; an unknown code returns an empty array.
category int|array required / as needed Category ids, or an array; omit for all. A slug becomes 0 and returns no rows.
category_slug string required / as needed Fetch by category slug (for example news); use either this or category, the core resolves it to an id first.
category_in bool true Subcategories are excluded by default; only an explicit true includes them.
limit int 10 Rows to fetch. Omitting it fetches every row: there is no default and no cap.
order string Top pinned first e.g. views desc; unknown fields are dropped and the default order applies.
flag string required / as needed Flag filter: top / recommend / hot; other values are ignored.
keyword string required / as needed Keyword: split on spaces and punctuation, terms are ANDed across searchable fields.
exclude int|array required / as needed Ids to exclude; several ids need an array such as [3, 5], while the comma string '3,5' uses only the first id. The generator in the tag tool turns an input of 3,5 into [3, 5] for you.
lang string Current language Language code, defaults to the current one; all returns all languages mixed.

3. Examples Every example can be copied as-is; the later ones are more advanced.

click the title to collapse / expand

Minimal

Start with the model and a small limit to confirm rows come back; _url on the row is the detail address.

<ul class="ry-list">
<?php foreach (content_list(['model' => 'news', 'limit' => 6]) as $item): ?>
    <li><a href="<?= e($item['_url']) ?>"><?= e(field($item, 'title')) ?></a></li>
<?php endforeach; ?>
</ul>

Product cards for one category, subcategories included

Store the result in a variable before looping; category takes an id, and category_in must be written out to include children.

<?php $items = content_list([
    'model'       => 'product',
    'category'    => 3,
    'category_in' => true,
    'limit'       => 8,
    'order'       => 'publish_time desc',
]); ?>
<ul class="ry-cards">
<?php foreach ($items as $item): ?>
    <li class="ry-card">
        <a href="<?= e($item['_url']) ?>">
            <?php if ($item['_thumb_url'] !== ''): ?>
                <img src="<?= e($item['_thumb_url']) ?>" alt="<?= e(field($item, 'title')) ?>" loading="lazy">
            <?php endif; ?>
            <h3><?= e(field($item, 'title')) ?></h3>
        </a>
        <p><?= e(field($item, 'summary')) ?></p>
    </li>
<?php endforeach; ?>
</ul>

Related block on a detail page, excluding the current item

On a detail page $item is the current record; exclude drops it and the block is printed only when rows remain.

<?php $related = content_list([
    'model'    => 'news',
    'category' => (int)$item['category_id'],
    'exclude'  => (int)$item['id'],
    'limit'    => 4,
]); ?>
<?php if ($related): ?>
    <aside class="ry-related">
        <h3>Related</h3>
        <ul>
        <?php foreach ($related as $row): ?>
            <li><a href="<?= e($row['_url']) ?>"><?= e(field($row, 'title')) ?></a></li>
        <?php endforeach; ?>
        </ul>
    </aside>
<?php endif; ?>

Popular list, picked with flag and sorted by views

Use flag together with order; flag knows only top, recommend, and hot, and any other value filters nothing.

<?php $hot = content_list([
    'model' => 'news',
    'flag'  => 'hot',
    'order' => 'views desc',
    'limit' => 5,
]); ?>
<ol class="ry-rank">
<?php foreach ($hot as $i => $item): ?>
    <li>
        <span class="ry-rank__no"><?= $i + 1 ?></span>
        <a href="<?= e($item['_url']) ?>"><?= e(field($item, 'title')) ?></a>
        <span class="ry-rank__views"><?= e(field($item, 'views')) ?></span>
    </li>
<?php endforeach; ?>
</ol>

4. What it does / when to use it

Use it for home page sections, sidebar rankings, and any list you fetch once without paging. It returns an array of rows, so a card grid, a timeline, and a carousel can share one query and render it differently. Do not use it when you need a page number or a total count, because it drops the paginator; that is what content_query is for. To show a single item, such as the one the current detail page is about, you do not need a tag at all because $item is already in scope.

5. Which pages it belongs on This is the question clients actually ask: "I am building the home page / a list page / a detail page — which tags do I use?"

click the title to collapse / expand
Page What that page is What this tag does there
Home Home page: hero, category blocks, latest content On the home page it usually sits in the hero, a category block, or a latest/featured section.
You use it to: Use it for home page sections, sidebar rankings, and any list you fetch once without paging
List pages Category list pages: listing, filters, pagination On a list page it lives in the list container or right next to the pagination bar.
You use it to: Use it for home page sections, sidebar rankings, and any list you fetch once without paging
Detail pages Content detail pages: body, specs, related items On a detail page it goes in the body area or in the related-items sidebar.
You use it to: Use it for home page sections, sidebar rankings, and any list you fetch once without paging
Single pages One-off pages such as About or Contact On a single page (About, Contact) it sits inside the content block.
You use it to: Use it for home page sections, sidebar rankings, and any list you fetch once without paging

Clicking a page name jumps to every tag for that page in the reference (the "By page" filter there). This page always shows everything about the tag, whatever that filter is set to.

6. How to use it (step by step)

  1. Set model first. It has to be a model code from Content Models in the admin (news, product, case and so on). A wrong code raises no error and simply returns an empty array, which renders as a blank area, so start with model plus a small limit, confirm that rows come back, and only then add filters.
  2. Always pass limit explicitly, because it is the only thing that decides how many rows you get. When it is missing, the query applies no upper bound and returns every matching row.
  3. To restrict the list to one category, pass its id as category and add 'category_in' => true. Only a truthy category_in expands the id to its subcategories, so without it you get that category alone. When all you have is a category slug, pass it as category_slug.
  4. Add flag to pick out pinned, featured, or popular items (top, recommend, hot), and order to sort by views, publish time, or price (views desc, price desc). With neither one the result comes back pinned first and then by sort order, which is exactly what the drag-and-drop ordering in the admin expects.
  5. On a detail page, exclude the item the visitor is already reading with exclude, otherwise the related block recommends the page they are on.
  6. Loop the rows with foreach, read values with field, and escape output with e(). Each row already carries _url, the full detail URL including the language prefix and category path, so it can be used directly as href.

7. Common pitfalls

  • Putting a category slug in category: the value is resolved as an id, so 'news' becomes 0 and the tag returns an empty list without any error, which looks exactly like an empty category. Pass slugs through category_slug, or pass the numeric id.
  • Assuming that an omitted limit means ten rows. The tag applies no default and no cap, so every matching row is fetched and rendered, which is what makes long lists slow.
  • Treating subcategories as included by default. Only a truthy category_in expands a category to its children; without it a parent category renders empty and you end up hunting for a data problem that does not exist. Pass the option explicitly instead of relying on a default.
  • order accepts only whitelisted columns (id, sort_order, publish_time, create_time, update_time, views, title, download_count, price). A misspelled field or an expression such as rand() is dropped silently and the default order takes over, which is why sorting sometimes appears to do nothing.
  • flag accepts only top, recommend, and hot. Any other value is ignored, and you get the whole list instead of the selection you asked for.

Note from the reference table Four corrections: limit has no default and no 100 cap (omitting it fetches every row); category takes ids only, so use category_slug for slugs; subcategories are excluded unless category_in is true; the default order is is_top desc, sort_order asc, id desc.

8. Real rendered output This section was rendered once on the server with this site real data; it is not a mock-up.

click the title to collapse / expand

This tag returns a data array (not HTML): the 3 newest rows on this site are below. Loop over it with foreach.

Open this page in a new window →

9. Where it already appears in your templates Grouped by components / page templates / template packs; the data comes from a script scan.

click the title to collapse / expand

Components 51 files / 68 calls 89% of tag calls live in components

  • templates/_shared/components/home-partners.php ×3 lines 29, 32, 38
  • templates/_shared/components/detail-content-common.php ×2 lines 112, 114
  • templates/_shared/components/detail-content-doc.php ×2 lines 227, 235
  • templates/_shared/components/detail-content-news-media.php ×2 lines 128, 136
  • templates/_shared/components/detail-content-news.php ×2 lines 113, 121
  • templates/_shared/components/detail-content-product-specs.php ×2 lines 224, 226
  • templates/_shared/components/detail-content-product.php ×2 lines 151, 153
  • templates/_shared/components/detail-content.php ×2 lines 37, 45

Template packs 1 files / 1 calls

  • templates/official/list_release_all.php ×1 lines 13

Click "See this code + preview": the left shows the real code around that call site (±12 lines, call line highlighted) and the right renders a real page preview with the current parameters.

Common combinations (generated from your real templates)

  1. Fetch the rows with this tag → render the cards with home-cases / sidebar-faq component(s)
  • templates/_shared/components/home-cases-cards.php
  • templates/_shared/components/sidebar-faq-list.php

11. Previous / next In group order; this is tag 1 of 56.

click the title to collapse / expand
Send an Enquiry