Skip to main content

Setting up type-specific index pages (v2)

By default the Tuskfish home page displays a single combined stream of all content types. If you want to set up an index page with a specific type of content (eg. news articles, downloads, or images), open the Listing controller trust_path/libraries/tuskfish/class/Tfish/Content/Controller/Listing and add a line to restrict the content type, for example to only list downloads you would use:

$this->viewModel->setType('TfDownload');

So the display() function would become:

public function display(): array
    {
        $cacheParams = ['page' => 'downloads'];

        $start = (int) ($_GET['start'] ?? 0);

        $this->viewModel->setStart($start);
        if (!empty($start)) $cacheParams['start'] = $start;
        
        // Restrict content to downloads.
        $this->viewModel->setType('TfDownload');
        $this->viewModel->setSort('date');
        $this->viewModel->setOrder('DESC');
        $this->viewModel->setSecondarySort('submissionTime');
        $this->viewModel->setSecondaryOrder('DESC');

        $id = (int) ($_GET['id'] ?? 0);
        
        if (!empty($id)) {
            $this->viewModel->setId($id);
            $cacheParams['id'] = $id;
            $this->viewModel->displayObject();
        } else {
            $this->viewModel->displayList();
        }

        return $cacheParams;
    }

Alternatively, you could set this up as a separate page with a custom URL, and keep the standard all-content Listing page intact.

Copyright, all rights reserved.