Re is out: see what's new Lifetime updates on every purchase Support replies within 24 hours Secure checkout via Gumroad 8,500+ sales since 2016

↑↓ Navigate ↵ Open Esc Close

All products
Re:Maily contact form builder is now available on WordPress.org See it live

Add a card style

Updated 3 min read 17 views

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

VariableWhat it is
$itemThe 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
$optionsThe values of the skin’s own settings
$indexThe item’s position in the grid
$configThe whole layout config
$sourceThe source object
$image_sizeThe 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' ] );
KindFilterTemplate
Card stylesforma_skins_stylesskins/{style}/skin.php
Filterforma_filters_stylesfilters/{style}/filter.php
Searchforma_search_stylessearch/{style}/search.php
Sortingforma_sort_stylessort/{style}/sort.php
Paginationforma_pagination_stylespagination/{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.

Was this article helpful?