📝 Homework: Navigation & Widgets
Build a Complete Navigation and Widget System
Apply your knowledge to create a fully functional theme with menus and widgets
Assignment Overview
In this homework assignment, you will implement a complete navigation and widget system for your WordPress theme. You'll create multiple menu locations, develop custom walker classes, register widget areas, and build custom widgets to enhance your theme's functionality.
Estimated Time
Part 1: Navigation Menu System
Required Tasks
- Register Menu Locations:
- Primary navigation menu
- Footer menu (single level)
- Social links menu
- Mobile menu (optional separate location)
- Implement Primary Navigation:
- Display in header.php with proper HTML structure
- Support multi-level dropdown menus
- Add mobile toggle button
- Include keyboard navigation support
- Create Mobile Menu:
- Responsive hamburger menu toggle
- Slide-in or dropdown mobile menu
- Touch-friendly menu items
- Close button or overlay click to dismiss
- Style Navigation Menus:
- Desktop horizontal navigation
- Hover effects for menu items
- Active/current page highlighting
- Smooth transitions and animations
functions.php - Menu Registration
// Register all menu locations
function mytheme_register_menus() {
register_nav_menus( array(
'primary' => __( 'Primary Menu', 'mytheme' ),
'footer' => __( 'Footer Menu', 'mytheme' ),
'social' => __( 'Social Links Menu', 'mytheme' ),
'mobile' => __( 'Mobile Menu', 'mytheme' ),
) );
}
add_action( 'after_setup_theme', 'mytheme_register_menus' );
Part 2: Custom Walker Class
Required Tasks
- Create Custom Walker Class:
- Extend Walker_Nav_Menu
- Override start_lvl() and end_lvl() methods
- Override start_el() and end_el() methods
- Add custom classes and attributes
- Walker Features:
- Add icon support using description field
- Include dropdown arrow for parent items
- Add data attributes for JavaScript
- Support for Bootstrap or custom framework
- Accessibility Enhancements:
- Add ARIA labels and roles
- Include aria-expanded for dropdowns
- Add screen reader text where needed
- Implement keyboard navigation support
Remember to test your walker class with different menu configurations and ensure it handles edge cases like empty menus or single-item menus.
Part 3: Widget Area Registration
Required Tasks
- Register Widget Areas:
- Primary sidebar (blog/archive pages)
- Page sidebar (static pages)
- 4 footer widget areas
- Header widget area
- Display Widget Areas:
- Create sidebar.php template
- Implement footer widgets in footer.php
- Add header widget area to header.php
- Check for active widgets before display
- Dynamic Footer Columns:
- Calculate active footer widgets
- Apply appropriate CSS classes
- Responsive column layout
- Equal height columns option
- Widget Area Styling:
- Consistent widget wrapper styles
- Widget title formatting
- List and link styles within widgets
- Responsive widget layouts
✓ Checkpoint 1
At this point, you should have:
- All menu locations registered and displaying
- Custom walker class functioning
- Widget areas registered and visible in admin
- Basic styling for menus and widgets
Part 4: Custom Widget Development
Required Widgets
- Recent Posts Widget:
- Title field
- Number of posts to display
- Show/hide post date
- Show/hide featured image
- Category filter option
- Social Links Widget:
- Fields for major social networks
- Icon display using dashicons or Font Awesome
- Open links in new window
- Custom title option
- Call to Action Widget:
- Title field
- Description/content area
- Button text and URL
- Button style options
- Background color picker (bonus)
Widget Class Structure
class MyTheme_Custom_Widget extends WP_Widget {
public function __construct() {
// Widget setup
}
public function widget( $args, $instance ) {
// Frontend output
}
public function form( $instance ) {
// Admin form
}
public function update( $new_instance, $old_instance ) {
// Save widget options
}
}
Project File Structure
mytheme/
├── inc/
│ ├── nav-walker.php - Custom walker class
│ ├── widgets.php - Widget registrations
│ └── widgets/
│ ├── recent-posts.php
│ ├── social-links.php
│ └── cta-widget.php
├── js/
│ ├── navigation.js - Menu toggle
│ └── widgets.js - Widget scripts
├── css/
│ ├── navigation.css
│ └── widgets.css
├── functions.php
├── header.php - Primary menu
├── footer.php - Footer widgets
├── sidebar.php - Main sidebar
└── sidebar-page.php - Page sidebar
📦 Deliverables
Navigation System
- 4 registered menu locations
- Responsive mobile menu
- Custom walker class
- Menu JavaScript file
Widget Areas
- 7+ registered widget areas
- Dynamic footer columns
- Sidebar templates
- Conditional display logic
Custom Widgets
- 3 custom widget classes
- Admin form controls
- Data validation
- Widget styling
Documentation
- Code comments
- README file
- Setup instructions
- Screenshot examples
🌟 Bonus Challenges
Complete these additional challenges for extra credit:
- Mega Menu Walker: Create a walker that supports mega menu layouts with columns
- AJAX Widget: Build a widget that loads content dynamically via AJAX
- Widget Visibility Control: Add options to show/hide widgets based on page type
- Sticky Navigation: Implement a sticky header with scroll effects
- Color Customization: Add Customizer options for menu and widget colors
- Widget Import/Export: Create functionality to export and import widget settings
Grading Rubric
| Component | Points | Criteria |
|---|---|---|
| Menu Registration | 15 | All menu locations properly registered and functional |
| Menu Implementation | 15 | Menus display correctly with proper HTML structure |
| Walker Class | 20 | Custom walker with all required methods and features |
| Widget Areas | 15 | Widget areas registered and displayed properly |
| Custom Widgets | 20 | Three functional custom widgets with admin controls |
| Responsive Design | 10 | Mobile menu and responsive widget layouts |
| Code Quality | 5 | Clean, commented, and well-organized code |
| Total | 100 |
📤 Submission Guidelines
- Package your theme: Create a ZIP file of your complete theme folder
- Include documentation: Add a README.md with setup instructions
- Test thoroughly: Ensure all features work on a fresh WordPress installation
- Take screenshots: Include screenshots of menus and widgets in action
- Submit on time: Upload your ZIP file before the deadline
Make sure to test your theme with WordPress Debug mode enabled (WP_DEBUG = true) and fix any errors or warnings before submission.
Helpful Resources
✓ Final Submission Checklist
Before submitting, ensure you have:
- ☐ All 4 menu locations registered and working
- ☐ Custom walker class implemented
- ☐ Mobile menu with toggle functionality
- ☐ All widget areas registered (7+)
- ☐ Dynamic footer column calculation
- ☐ 3 custom widgets created and registered
- ☐ Responsive CSS for all components
- ☐ JavaScript for menu interactions
- ☐ Proper data sanitization in widgets
- ☐ Code comments and documentation
- ☐ No PHP errors or warnings
- ☐ Screenshots included
- ☐ README file with instructions
Good Luck!