Use case: Custom featured content gallery
Notice: this article is written for advanced WordPress users, and assumes some prior knowledge. Specifically, you should know how to do the following things: Understanding and modifying PHP-code in WordPress templates, creating and using dynamic sidebars in functions.php, and working with widgets.
Another note: there are plugins that take care of featured content galleries automatically, but they don’t offer the kind of fine-grained control over the HTML that we like to have. This is a professional scenario.
Oh, and he wants it done yesterday.
Examining the static HTML, you notice that the repeating element that holds the content looks something like this:
As there is no standard way to render that kind of HTML in WordPress, the only way to solve this is to write custom code that fetches articles and pages based on, for example, a custom field, and render them in a loop.
You can do it faster and easier with Dynamic Content Widget.
Step 1: Create subtemplate
Create a file called ‘gallery-item.php’ in your theme directory.
Copy and paste the HTML of the repeating element into this file, replacing the static elements with the dynamic ones in the subtemplate. Here’s a hypothetical example: