BootstrapNavGenerator
The Bootstrap 5 Navigation Menu Generator is a PHP class that simplifies the process of creating dynamic, responsive navigation menus for websites using Bootstrap 5.
Install / Use
/learn @ErikThiart/BootstrapNavGeneratorREADME
Bootstrap 5 Navigation Menu Generator
Table of Contents
- Introduction
- Features
- Requirements
- Installation
- Usage
- Configuration Options
- Examples
- Customization
- Contributing
- License
Introduction
The Bootstrap 5 Navigation Menu Generator is a PHP class that simplifies the process of creating dynamic, responsive navigation menus for websites using Bootstrap 5. It provides a flexible and easy-to-use interface for generating customizable navigation bars with support for dropdown menus, search forms, and active item highlighting.
Features
- Dynamic generation of Bootstrap 5 compatible navigation menus
- Support for dropdown menus (multi-level)
- Customizable brand/logo section
- Light and dark theme options
- Fixed positioning (top or bottom)
- Responsive design with customizable breakpoints
- Search form integration
- Icon support (compatible with Bootstrap Icons or other icon libraries)
- Dynamic active item highlighting based on current URL
- Custom CSS class support for additional styling
Requirements
- PHP 7.0 or higher
- Bootstrap 5 CSS and JS files
- (Optional) Bootstrap Icons or another icon library for menu item icons
Installation
- Download the
BootstrapNavGenerator.phpfile. - Place it in your project directory where you keep your PHP classes.
- Include the file in your PHP script:
require_once 'path/to/BootstrapNavGenerator.php';
Usage
Here's a basic example of how to use the Bootstrap 5 Navigation Menu Generator:
<?php
require_once 'BootstrapNavGenerator.php';
$nav = new BootstrapNavGenerator();
$nav->setBrand('My Website', '/');
$nav->addMenuItem('Home', '/');
$nav->addMenuItem('About', '/about');
$nav->addMenuItem('Services', '/services', [
['label' => 'Web Design', 'url' => '/services/web-design'],
['label' => 'SEO', 'url' => '/services/seo']
]);
$nav->addMenuItem('Contact', '/contact');
echo $nav->generateMenu();
?>
Configuration Options
Setting the Brand
$nav->setBrand('My Website', '/', 'path/to/logo.png');
Changing the Theme
$nav->setTheme('dark'); // or 'light'
Fixed Positioning
$nav->setFixed('top'); // or 'bottom'
Container Type
$nav->setContainer('lg'); // 'fluid', 'sm', 'md', 'lg', 'xl', 'xxl'
Expansion Breakpoint
$nav->setExpandPoint('md'); // 'sm', 'md', 'lg', 'xl', 'xxl'
Adding a Search Form
$nav->addSearchForm('Search our site...');
Adding Custom Classes
$nav->addCustomClass('my-custom-navbar');
Examples
Full Example with All Features
<?php
require_once 'BootstrapNavGenerator.php';
$nav = new BootstrapNavGenerator();
$nav->setBrand('My Website', '/', 'path/to/logo.png');
$nav->setTheme('dark');
$nav->setFixed('top');
$nav->setContainer('lg');
$nav->setExpandPoint('md');
$nav->addMenuItem('Home', '/', [], 'bi bi-house');
$nav->addMenuItem('About', '/about', [], 'bi bi-info-circle');
$nav->addMenuItem('Services', '/services', [
['label' => 'Web Design', 'url' => '/services/web-design', 'icon' => 'bi bi-brush'],
['label' => 'SEO', 'url' => '/services/seo', 'icon' => 'bi bi-search']
], 'bi bi-gear');
$nav->addMenuItem('Contact', '/contact', [], 'bi bi-envelope');
$nav->addSearchForm('Search our site...');
$nav->addCustomClass('custom-navbar');
echo $nav->generateMenu();
?>
Customization
You can further customize the navigation menu by extending the BootstrapNavGenerator class or by modifying the existing methods to suit your specific needs.
Contributing
Contributions to improve the Bootstrap 5 Navigation Menu Generator are welcome. Here's how you can contribute:
-
Reporting Issues: If you find a bug or have a suggestion for improvement, please open an issue in the GitHub repository. Provide as much detail as possible, including steps to reproduce the issue if applicable.
-
Submitting Pull Requests: If you'd like to contribute code:
- Fork the repository
- Create a new branch for your feature or bug fix
- Make your changes
- Submit a pull request with a clear description of the changes
-
Improving Documentation: If you notice areas where the documentation could be improved or expanded, feel free to suggest changes.
-
Sharing Ideas: If you have ideas for new features or improvements, open an issue to discuss them.
Before making significant changes, it's a good idea to open an issue to discuss the proposed changes with the maintainers.
Please ensure that your contributions adhere to:
- The existing code style
- Best practices for PHP and Bootstrap 5
- Proper documentation of new features or changes
By contributing to this project, you acknowledge that your contributions will be released under The Unlicense, effectively placing them in the public domain.
Thank you for helping to improve the Bootstrap 5 Navigation Menu Generator!
License
This project is licensed under The Unlicense - see the UNLICENSE file for details.
This means that you are free to do whatever you want with this software. You can use it, modify it, distribute it, or sell it without any restrictions. The authors have released it into the public domain, dedicating all their rights to the work to the public domain worldwide.
For more information about The Unlicense, visit https://choosealicense.com/licenses/unlicense/.
For more information or support, please open an issue in the GitHub repository.
Related Skills
node-connect
351.4kDiagnose OpenClaw node connection and pairing failures for Android, iOS, and macOS companion apps
frontend-design
110.7kCreate distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.
openai-whisper-api
351.4kTranscribe audio via OpenAI Audio Transcriptions API (Whisper).
qqbot-media
351.4kQQBot 富媒体收发能力。使用 <qqmedia> 标签,系统根据文件扩展名自动识别类型(图片/语音/视频/文件)。
