Add a card style
A card style (skin) is a folder with a skin.php. This page builds one called Work 1 in three steps.
1. Register it
// functions.php
add_filter( 'forma_skins_styles', fn( $styles ) => $styles + [
'work-1' => [ 'label' => 'Work 1', 'group' => 'Work' ],
] );
The style now shows in the Skin list, under a Work heading.
2. Write skin.php
Forma prints the <article class="forma-card"> around skin.php, so the file holds only what goes inside the card. Print the common parts with forma_item_part(), and wrap what should be clickable in forma_link_start() and forma_link_end(), so the lightbox and the layout’s Click action keep working.
<?php
// your-theme/forma/skins/work-1/skin.php
?>
<?php echo forma_link_start( $item, 'work-card__media' ); ?>
<div class="forma__media">
<?php forma_item_part( 'image', $item ); ?>
<?php forma_item_part( 'video', $item ); ?>
</div>
<?php echo forma_link_end( $item ); ?>
<div class="work-card__body">
<?php forma_item_part( 'terms', $item, [ 'class' => 'work-card__terms' ] ); ?>
<?php forma_item_part( 'title', $item, [ 'class' => 'work-card__title', 'tag' => 'h3' ] ); ?>
<p class="work-card__year"><?php echo esc_html( $item['year'] ); ?></p>
</div>
3. Style it
A style.css next to skin.php loads only on pages that use the style. A script.js there works the same way.
/* your-theme/forma/skins/work-1/style.css */
.work-card__body {
padding-block: 16px;
}
.work-card__title {
margin: 4px 0 0;
font-size: 20px;
}
To give the style options in the editor, such as a corner radius or a “Show the year” toggle, add a settings.php: see Skin settings.
What skin.php gets
| Variable | What it is |
|---|---|
$item | The item: id, type, title, url, image_id, excerpt, date, object (the WP_Post or other original), plus terms, tags, year, datetime, format, author, comments_count, count and placeholder |
$options | The values of the skin’s own settings |
$index | The item’s position in the grid |
$config | The whole layout config |
$source | The source object |
$image_size | The image size the layout asks for |
The parts for forma_item_part() are image, video, title, terms, tags, date, count and excerpt. Each is a template in item-parts/ that your theme can override.
Styles for the controls
Filters, search, sorting and pagination take styles the same way: a filter registers the style, and a folder of the same name holds its template.
add_filter( 'forma_filters_styles', fn( $styles ) => $styles + [ 'pills' => 'Pills' ] );
| Kind | Filter | Template |
|---|---|---|
| Card styles | forma_skins_styles | skins/{style}/skin.php |
| Filter | forma_filters_styles | filters/{style}/filter.php |
| Search | forma_search_styles | search/{style}/search.php |
| Sorting | forma_sort_styles | sort/{style}/sort.php |
| Pagination | forma_pagination_styles | pagination/{style}/numbers.php, load-more.php, infinite.php |
A style without a template of its own falls back to the default one, so a pagination style can start with just a style.css.