Custom website header template in locations

The pagemycatheader plugin for Cotonti CMF allows you to flexibly replace the default header.tpl with a custom one on pages of a selected parent category and all its subcategories, including individual articles.

Page My Custom Categories and Articles Header Template (pagemycatheader)

version-2.3.0 PHP-8.4+ Cotonti_Siena-0.9.26+

A plugin for Cotonti Siena that flexibly replaces the header template header.$location.tpl for pages in the selected parent Page category and all its child categories, including individual articles. Supports automatic SEO URL parsing and URL parameters (?c=, ?id=), does not require core modifications, and integrates with any theme.

 

DEMO


Description & Purpose

pagemycatheader is an extension for Cotonti Siena that allows you to:

  • Use different header templates (header.tpl) for various sections of your site;
  • Automatically substitute the header for the chosen parent category and all its descendants;
  • Keep your theme structure clean—no need to create templates for every subcategory.

The plugin is ideal for documentation sites, blogs, portals, or any project where unique section headers matter.


Key Features

  • Automatic header replacement: for pages, categories, and articles within the chosen parent category’s tree;
  • SEO URL support: precise category detection in URLs;
  • Legacy compatibility: works for old links like ?c=category or ?id=page;
  • Flexible configuration: just one parameter to set – parent category code (parentcat);
  • No core changes required;
  • Compatible with: PHP 8.4+, Cotonti Siena ≥0.9.26.

Template examples

/themes/2waydeal/header.list.tpl

  • Default template for article lists in any category, if $cfg['enablecustomhf'] = true;

/themes/2waydeal/header.pages.tpl

  • Default template for any individual page/article in any category, if $cfg['enablecustomhf'] = true;

/themes/2waydeal/header.tpl

  • Default fallback template, always required, DOES NOT depend on $cfg['enablecustomhf'] = true;

/themes/2waydeal/header.page.user-guide.tpl

  • Template selected via pagemycatheader plugin, if $cfg['enablecustomhf'] = true;


Installation

  • Copy plugin files
    Place the pagemycatheader folder in your site's plugins/ directory:

    plugins/pagemycatheader/
    ├─ pagemycatheader.setup.php
    ├─ pagemycatheader.functions.php
    └─ pagemycatheader.header.first.php
    

     

  • Activate the plugin
    • Go to Cotonti Admin Panel, "Plugins" menu.
    • Enable pagemycatheader.
  • Configure parameter parentcat
    In plugin settings, specify the parent category code, e.g. user-guide.
    This value must exactly match the code in your Cotonti structure.
  • Create the template
    Generate the file:

    themes/your_theme/header.page.user-guide.tpl
    

     

    1. Filename must be strictly header.page. + category code + .tpl
    2. Clear cache
      • After installation or template changes, clear Cotonti's cache:
        Admin Panel → Tools → Clear Cache (Clear Cache).

How It Works: Logic & Details

  • Hook header.first
    The plugin works at the "header.first" stage (header generation). This gives maximum flexibility before the theme loads.
  • Category detection
    • SEO URL:
      Gets segment after language code, e.g. /ru/user-guide/... means user-guide.
    • Legacy URLs:
      If passing ?c, takes this as the category; if ?id, gets category from DB.
  • Parent check Using the function:

    pagemycatheader_is_descendant($cat, $parentcat)

     

  • Checks:
    • Is current category the parent;
    • Is it a descendant (any nesting level).
  • Template override
    When matched, sets Cotonti variable:

    Cot::$env['location'] = 'page.' . $parentcat;
    

     

Cotonti then loads the template:

header.page.user-guide.tpl
  1. All descendants and the parent category use this header.
  2. Legacy support: If SEO URL is not present, or on old-style (?c= or ?id=), plugin logic is the same—the category is taken from parameter or page ID.

Example Structure & Usage

Example URLs:

  • /ru/user-guide/projects-manual/tasks-general → template: header.page.user-guide.tpl
  • /index.php?c=projects-manual → if projects-manual is a child of user-guide, header is switched
  • /index.php?id=123 → category is fetched by ID, then tree check

Summary:
If the page belongs to user-guide category or any descendant, the plugin uses header.page.user-guide.tpl for the header.


Settings

ParameterTypeDescription
parentcatstringThe code of the parent Page category (e.g. user-guide)
  • All descendants automatically inherit the parent’s template.
  • You can create separate templates for different parent categories.

Possible Issues & Solutions

IssueCauseSolution
Custom header not loadedWrong category code, no template fileCheck parentcat value and template file existence
Doesn't work on subcategoriesWrong URL order or $_GET['c'] empty (SEO URLs)Plugin parses URL itself; not dependent on $_GET['c']
File not foundWrong directory or filenameMust be strictly themes/your_theme/header.page.user-guide.tpl
Default header after theme changeTemplate file remained in old themeCopy the template to every theme you use
Doesn't work on parent category rootURL driver specifics or missing slashFixed—now works for either URL format
Cache not updatedTemplate changes not appliedClear Cotonti's cache in admin panel

FAQ & Tips

  • Can the plugin use multiple parent categories at once?
    — No, current version works with one parent category per installation. For different branches, use multiple templates and change parentcat.
  • Nested (child) categories?
    — Any level of nesting is supported; parent chain search is performed.
  • Permissions?
    — The plugin only affects the header template. Category permissions are handled by Cotonti.
  • If no custom header is set?
    — Standard header.tpl will be used.

Limitations

  • Works only with the page module;
  • Does not check user permissions;
  • Does not affect other modules (e.g. news, forums, etc.);
  • Only one template override for the selected parent category at a time.

Requirements

  • Cotonti Siena ≥0.9.26
  • PHP ≥8.4
  • Modules: page and structure (installed and enabled)

File Structure

plugins/pagemycatheader/
├─ pagemycatheader.setup.php # Metadata, registration, settings
├─ pagemycatheader.functions.php # Core: tree relationship checks
├─ pagemycatheader.header.first.php # Main logic: URL handling and header substitution

License

BSD License © 2025 webitproff


Author, Support, Feedback

Author: webitproff
GitHub: https://github.com/webitproff/cotonti-pagemycatheader
For questions, bug reports, suggestions — GitHub Issues.


Useful Links


This plugin helps you flexibly style your sections and their content without unnecessary template duplication!
If you need a dynamic header for a group of categories, pagemycatheader is the solution.

If the plugin is useful to you, give it a ⭐ on GitHub!


Copyright

© webitproff, 29 Nov 2025, BSD License.


You can hire me or suggest a project

Send a message on this page

4 minutes read Sodium Carbonate

Comments (0)

No comments yet
Only registered users can post new comments

Content author

webitproff

Offline

Sodium Carbonate

Last logged: 2026-07-19 01:57

  • Page published: 2025-11-29 12:17
  • Last update: 2026-04-27 17:22
  • Language:

Similar pages

Файл functions.custom.php в Cotonti
1 В файл functions.custom.php в Cotonti обычно добавляют дополнительные пользовательские функции, которые не входят в
Тип custom в переменных конфигурации
2 Тип 'custom' в переменных конфигурации Возможности типа 'custom' Новый тип custom предоставляет
Руководство по пользовательским функциям functions.custom.php в Cotonti
3 Руководство по пользовательским функциям CotontiЭто руководство содержит подробное описание четырех функций,
Файл header.php в Cotonti
4 Файл header.php в системной папке Cotonti CMF отвечает за формирование и обработку заголовка страницы сайта, который
HTML-шаблон header.tpl в Cotonti
5 Основное назначение файла и его место в системе Cotonti: Файл header.tpl — это важный элемент в системе шаблонов