Welcome to Genhike Sports

Content Date

← Back to the tag reference

Hand-written Includes in-depth notes

Content Date content_date Used inside components 69 host files / 82 calls

Output the publish time of a content item, or the time of a named field, in the requested format.

content_date($item, $format = null)

Pages List pages Detail pages Archive

Used in
List pages / Detail pages / Archive
Defined in
core/tpl_functions.php:415
Core method
Tpl::date()
How do I read these repository paths?

All paths are relative to the site root. Open core/tpl_functions.php at line 415 to see the definition of content_date(). 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
Content row; publish_time first, then create_time.
PHP date format; empty = the date_format language term.
Generated code

Now generating: content_date

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 2 parameters, one per row; scroll sideways on narrow screens.

click the title to collapse / expand
Parameter Type Default Description
item array required / as needed Content row; publish_time first, then create_time.
format string From the site settings PHP date format; empty = the date_format language term.

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

click the title to collapse / expand

Minimal

With no format given it follows the language setting, printing 2026-10-01 in Chinese and Oct 1, 2026 in English.

<?php $ryDate = (string)content_date($item); ?>
<time class="ry-date" datetime="<?= e($ryDate) ?>"><?= e($ryDate) ?></time>

Machine-readable value

Keep the visible text in the language format and the attribute in a machine-readable format, so readers and crawlers both get what they need.

<?php $ryIso = (string)content_date($item, 'Y-m-d\TH:i:sP'); ?>
<time class="ry-date" datetime="<?= e($ryIso) ?>"><?= e(content_date($item)) ?></time>

Date block on a list card

Check the value first, then print the block, so the card never shows a label with nothing after it.

<?php $ryDate = (string)content_date($item, 'Y-m-d'); ?>
<?php if ($ryDate !== ''): ?>
    <span class="ry-card-date"><?= e($ryDate) ?></span>
<?php endif; ?>

4. What it does / when to use it

Use it for the date on a list card, the publish line under a detail page title, sitemap entries, and archive pages. It reads the format configured for the current language, which prints 2026-10-01 on the Chinese site and Oct 1, 2026 on the English site, so a single template serves both languages without a branch. Pass an explicit format only when the design or a machine consumer needs one fixed shape. The value comes from the publish time with the create time as a fallback, so custom date fields such as a project completion date or a deadline need another tag.

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
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 the date on a list card, the publish line under a detail page title, sitemap entries, and archive pages
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 the date on a list card, the publish line under a detail page title, sitemap entries, and archive pages
Archive Tag pages and model archives On an archive page (a tag page or model archive) it renders the aggregate list.
You use it to: Use it for the date on a list card, the publish line under a detail page title, sitemap entries, and archive pages

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. Call content_date($item) with no format first. It returns the configured format for the current language, so the template never needs to test the language itself.
  2. Pass a PHP date format as the second argument when the design fixes one shape, for example content_date($item, 'Y-m-d') or content_date($item, 'M j, Y').
  3. Use a machine-readable format for a datetime attribute or structured data, for example content_date($item, 'Y-m-d\TH:i:sP'), because crawlers cannot parse a display format.
  4. Keep custom date fields out of it. The tag only reads the publish and create times, so read a field such as project_date with field($item, 'project_date').
  5. Wrap the output in e() and write the machine-readable value into a datetime attribute next to the visible text so search engines see an unambiguous timestamp.

7. Common pitfalls

  • Printing a label before checking the value. The tag returns an empty string when the row has neither a publish nor a create time, which leaves a half-finished line reading Published:. Guard the whole row with if ($ryDate !== '').
  • Mixing it with a raw date() call such as date('Y-m-d', strtotime($item['publish_time'])). That bypasses the per-language setting, so the English page silently falls back to the Chinese date shape and one page ends up with two date styles.
  • Hard-coding a display format instead of using the setting, which prints the same shape on both sites and makes the translation look unfinished.
  • Forgetting to escape literal letters in a format string. Letters that are also format characters, such as T, P, or D, must be backslash-escaped or the output turns into a timezone offset or a weekday number.

Note from the reference table Correction: there is no field-selection parameter - the code reads publish_time, then create_time. The default format is the date_format language term (Y-m-d in Chinese, M j, Y in English), overridable in the backend language texts, not a backend setting. The example's date() hits PHP's native function and fails; use content_date().

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

Formatted with the date format configured in the admin.

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 69 files / 82 calls 89% of tag calls live in components

  • templates/_shared/components/detail-content-download.php ×2 lines 419, 636
  • templates/_shared/components/detail-content-news-brief.php ×2 lines 91, 350
  • templates/_shared/components/detail-content-news-media.php ×2 lines 86, 554
  • templates/_shared/components/detail-content-news.php ×2 lines 74, 534
  • templates/_shared/components/detail-content-video-cinema.php ×2 lines 42, 361
  • templates/_shared/components/detail-content-video-player.php ×2 lines 60, 694
  • templates/_shared/components/detail-content-video.php ×2 lines 557, 685
  • templates/_shared/components/detail-related-feature.php ×2 lines 158, 183

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.

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

click the title to collapse / expand
Send an Enquiry