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

Recipes

Updated 2 min read 27 views

Short examples for jobs themes ask about often. Each goes in the theme’s functions.php.

Show a field of your own on each card

forma_item_data changes the data a card gets. Add the value there, then print it in skin.php:

add_filter( 'forma_item_data', function ( $item, $config, $source ) {
	if ( $item['object'] instanceof WP_Post ) {
		$item['client'] = get_post_meta( $item['id'], 'client', true );
	}

	return $item;
}, 10, 3 );
<?php if ( ! empty( $item['client'] ) ) : ?>
	<p class="work-card__client"><?php echo esc_html( $item['client'] ); ?></p>
<?php endif; ?>

Show a project’s view count

The count is in the _forma_views post meta:

<?php $views = (int) get_post_meta( $item['id'], '_forma_views', true ); ?>
<span class="work-card__views"><?php echo esc_html( number_format_i18n( $views ) ); ?></span>

forma_query_args changes the WP_Query of a posts or Media source. This applies to every grid of the Portfolio source:

add_filter( 'forma_query_args', function ( $query_args, $query, $args, $source_id ) {
	if ( 'portfolio' === $source_id ) {
		$query_args['meta_query'][] = [ 'key' => 'featured', 'value' => '1' ];
	}

	return $query_args;
}, 10, 4 );

Mark some items with a class

add_filter( 'forma_item_classes', function ( $classes, $item, $config ) {
	if ( has_term( 'awards', 'portfolio_category', $item['id'] ) ) {
		$classes[] = 'is-award';
	}

	return $classes;
}, 10, 3 );

Change the empty message

add_filter( 'forma_empty_message', fn() => __( 'Nothing here yet. Try another category.', 'my-theme' ) );

Load your own files with a grid

The forma_enqueue action runs on pages that show a grid, with the layout’s config:

add_action( 'forma_enqueue', function ( $config ) {
	wp_enqueue_script( 'my-theme-grid', get_theme_file_uri( 'js/grid.js' ), [], '1.0', true );
} );

Set the breakpoints in code

add_filter( 'forma_breakpoints', fn( $breakpoints ) => array_merge( $breakpoints, [ 'mobile' => 640 ] ) );

The keys are tablet_landscape, tablet and mobile, in px. Each must be smaller than the one above it.

Was this article helpful?