-
Notifications
You must be signed in to change notification settings - Fork 18
Theme Functionality
While the main code base is object-oriented, we still need simple functions for trivial things.
This functionality is placed inside inc folder. There are 3 files inside be default:
helpers.phphooks.phptemplate-funcs.php
Helpers are simple functions, which perform some simple data processing. They can be some data formatters, format adapters, or similar.
Example: we have a product catalogue on our site (no e-commerce), and we need to have a lot of product banners over the site. Each banner prints price along with all other information and you want to be sure it has the same format like "{currency} {amount with 2 digits}". You can create a simple helper function {prefix}_price(), and use it inside the templates
Most hooks are registered inside the app. However, there are some hooks, which are not important or have a very generic definition. We place such hooks inside this file.
Example: Body class adjustment based on some logic.
Example: Excerpt length hook.
The main part of Wordpress templates is The Loop. Functions, that generate some content for post/pages or custom post types, are added here.
Example: {prefix}_posted_on() printed formatted post date
Available functions by default:
| Function | Description |
|---|---|
| {prefix}_posted_on() | Print formatted post date and post author |
| {prefix}_entry_footer() | Print formatted post categories, tags and other meta info |