Add An Options Page To Your Theme With The NHP Theme Options Framework
On the framework home page Lee acknowledges other great option frameworks such as Options Framework Theme and The UpThemes Framework though points out that neither of them provided him with the extendibility he needed. Specifically he wanted:
- Section Tabs – Each settings section to have its own “tab” which can be clicked through.
- Use the WordPress Core Settings API – The settings to use the core WordPress functions for creating/editing settings (no point reinventing the wheel).
- Custom Error Handling – To be able to display error totals and custom messages for each section/setting.
- Easily Extendable – To be able to extend the framework for custom use applications, settings fields and custom validation.
- Customisable – To be able to customise the functionality and style without hacking at the core.
Adding the options to a theme is incredibly easy. You first need to upload the theme-options.php file and options directory to your theme folder (e.g. www.yoursite.com/wp-content/themes/twentyeleven/themeoptions.php and www.yoursite.com/wp-content/themes/twentyeleven/options). Then you need to request the theme-options.php file from your theme via your theme functions.php file.
require( dirname( __FILE__ ) . '/theme-options.php' );
Once you have added the above line to your theme functions file, you will see a new Theme Options page underneath your appearance section. The framework supports a 28 field types including textareas, check boxes, dates, colours, post type selector and info field.
The framework includes lots of validation classes such as no HTML, date validation, colour validation and string replacement.
The framework comes with an import and export system built in so that users can save what their configurations.
A number of custom message phrases are included with the framework such as ‘Settings Saved’ and ‘Settings Imported’.
I’ve not developed a theme with a custom options page so I am not in a position to compare it to other option frameworks out there. It does appear to be a very good option though due to it’s flexibility and number of field types to choose from. The code has comments throughout and it is well documented too so you shouldn’t have difficulties modifying it for your own website theme.
More information can be found at the link below.