GeniXCMS

Archives Class

categoryAPI edit_calendar31 Mar 2026

Archives Class


The Archives class manages the categorization and retrieval of posts by their publication date (month and year). It includes a caching mechanism for archive lists to optimize database performance.

Core Features

  • Dynamic Archive Listing: Generates lists of months/years where content was published.
  • Automated Caching: Stores the archive structure in a JSON-encoded system option, which is automatically updated every 24 hours.
  • Post Support: Currently optimized for content of type 'post'.

Methods

List Method

Usage: echo Archives::list(int $max, string $type = 'post');

Returns an HTML <ul> list of links to monthly archives.

  • It reads data from the archives_list system option.
  • Automatically formats month names using the Date::monthName() utility.

Generate Method

Usage: Archives::generate(string $type = 'post');

Triggers an update to the archive cache if more than 24 hours have passed since the last update.

Validate Method

Usage: Archives::validate(int $month, int $year);

Return: bool

Checks if any posts actually exist for the given month and year. This is used by the router to prevent empty archive pages.

Internal Workflow

  1. Extraction: The fetchData() method queries the database using GROUP BY Month(date), Year(date) to find all unique publication periods.
  2. Persistence: The resulting structure is saved as a JSON string in the archives_list option.
  3. Trigger: The class constructor calls generate() on every request to ensure the cache stays fresh without requiring manual intervention.