Page My Custom Categories and Articles Header Template (pagemycatheader)

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
- Filename must be strictly
header.page. + category code + .tpl - 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
- All descendants and the parent category use this header.
- 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
| Parameter | Type | Description |
| parentcat | string | The 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
| Issue | Cause | Solution |
| Custom header not loaded | Wrong category code, no template file | Check parentcat value and template file existence |
| Doesn't work on subcategories | Wrong URL order or $_GET['c'] empty (SEO URLs) | Plugin parses URL itself; not dependent on $_GET['c'] |
| File not found | Wrong directory or filename | Must be strictly themes/your_theme/header.page.user-guide.tpl |
| Default header after theme change | Template file remained in old theme | Copy the template to every theme you use |
| Doesn't work on parent category root | URL driver specifics or missing slash | Fixed—now works for either URL format |
| Cache not updated | Template changes not applied | Clear 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