Teft Cards is a Gutenberg module that adds the a simple card grid to client projects.
The theme block includes two “Block Styles” - Light and Dark. You can switch between them by clicking “Change block type or style” up in the top left corner.
If you don’t want all included styles you can unregister them by using JavaScript:
wp.blocks.unregisterBlockStyle( 'teft/cards-theme', 'light' );
wp.blocks.unregisterBlockStyle( 'teft/cards-theme', 'dark' );
The same way you can unregister styles you can add you own:
wp.blocks.registerBlockStyle( 'teft/cards-theme', {
name: 'fancy',
label: 'Fancy'
} );
See block style variations documentation for more info.
If you want to run a different default card you have the option to change this.
add_filter( 'teft/cards/default_card_type', function() {
return 'my-custom-default-card';
} );
Shadow on cards can be disabled with the filter render_card_shadow
.
add_filter( 'render_card_shadow', '__return_false' );
Select what post types to show in the post selector.
add_filter( 'teft/cards/post_selector/post_types', function() {
return [ 'post', 'page' ];
} );
Enable the multisite search (extended search query) – you still need to use the hook below, teft/cards/extend_post_selector_results
as well (or similar) to implement the multisite search logic.
add_filter( 'teft/cards/post_selector/multisite_search', '__return_true' );
If you want to extend the results returned by the post selector – for example, if you also want the user to have access to tagged posts from another blog on the multisite – you can use the following filter:
add_filter( 'teft/cards/extend_post_selector_results', function( array $posts, array $query_args, string $class_name ) {
$main_site_id = get_main_site_id(); // we want the template part from the main site.
if ( get_current_blog_id() === $main_site_id ) {
return $posts; // we don't want to re-add posts for the main site, so we just return the original result set.
}
switch_to_blog( $main_site_id );
// if you need to modify the query, ie. to search for specific tagged posts, do that here.
$main_site_posts = ( new \WP_Query( $query_args ) )->posts;
if ( ! empty( $main_site_posts ) ) {
foreach ( $main_site_posts as $main_site_post ) {
$main_site_post->blog_id = $main_site_id;
$posts[] = $main_site_post;
}
}
restore_current_blog();
return $posts;
}, 10, 3 );
The theme block includes three “Variations” (Heading with text and grid, Heading with grid, Grid only).
You can register more (or deregister the default ones) using the variations API.
You can create custom blocks to insert into the grid. To add them to the allowed blocks list use the filter teft/cards/grid/allowed_blocks
.
add_filter( 'teft/cards/grid/allowed_blocks', function() {
return [ 'my-awesome/block' ];
} );
The custom blocks are responsible to set number of columns/rows.
wp.hooks.addFilter( 'teft.cards.allowedSizes', 'myTheme', function() {
return [ 3, 4, 6 ];
} );
To add the rows controls the theme need to define what column sizes the row options should be allowed on.
add_filter( 'teft/cards/allow_rows_on_columns', function() {
// Allow to define rows on 8 columns (66%).
return [ 8 ];
} );
wp.plugins.unregisterPlugin( 'teft-cards-meta-image' );
wp.plugins.unregisterPlugin( 'teft-cards-meta-title' );
wp.plugins.unregisterPlugin( 'teft-cards-meta-excerpt' );
import { registerPlugin } from '@wordpress/plugins';
import { Fill } from '@wordpress/components';
registerPlugin( 'my-cards-meta-plugin-name', {
render() {
return (
<Fill name="teft-cards-meta">
My field
</Fill>
);
},
} );
wp.hooks.addFilter( 'teft.customCards.allowedBlocks', 'myTheme', function(allowedCustomCardBlocks) {
allowedCustomCardBlocks.push('my-new-block');
return allowedCustomCardBlocks;
}, 1 );
// Enable custom cards functionality.
define( 'TEFT_CARDS_CUSTOM', true );
function filter_allowed_custom_card_blocks( array $blocks ) : array {
$new_blocks = [
'teft-cards-custom-cards/my-new-block',
];
return array_merge( $new_blocks, $blocks );
}
const modifyAllowedCustomCardBlocks = ( allowedCustomCardBlocks ) => {
allowedCustomCardBlocks.push('teft-cards-custom-cards/my-new-block');
return allowedCustomCardBlocks;
};
wp.hooks.addFilter(
'teft-custom-cards-allowed-blocks',
'dekode/filter-custom-card-block',
modifyAllowedCustomCardBlocks
);