Post Dynamic Part

Displays a post label from a type, meta, term, attribute, a static string, or even a custom PHP filter.

Last modified: June 5, 2024

This blocks can be used as helper block.
E.g it is used in T2 featured post block, in other T2 elements, and in the templates.

link Block name

t2/post-dynamic-part

link Attributes

link Example Usage

Show the current post type in any part of the content, template, or block:

<!-- wp:t2/post-dynamic-part {"source":"attribute","target":"post_type"} /-->

Show a maximum of two kitchen-category terms inside the kitchen-sink card, and also allow for links to terms archives:

<!-- wp:t2/post-dynamic-part {"source":"term","target":"kitchen-category","limit":"2","link":true} /-->

Show the current archive label inside the index.html template, making it wide and applying spacing.

<!-- wp:t2/post-dynamic-part {"tag":"h1","source":"object","target":"label","align":"wide","style":{"spacing":{"margin":{"top":"var:preset|spacing|lg","bottom":"var:preset|spacing|md"}}}} /-->

Show some custom content using a PHP filter in the project

<!-- wp:t2/post-dynamic-part {"source":"filter","target":"phone_format"} /-->

link Example Usage with PHP Filter

When using the PHP filter as source, basically the sky is the limit, you can create programmatically in the projects any filters you need for exposing in a very controlled way whatever needs to be connected to a post.

\add_filter( 't2/block/post_dynamic_part/filter_output/phone_format', __NAMESPACE__ . '\\phone_format', 10, 4 );

/**
 * Custom phone format on the card.
 *
 * @param  string $content    The initial content.
 * @param  int    $post_id    The WP_Post ID.
 * @param  array  $attributes The block attributes.
 * @param  array  $context    The block context.
 * @return string
 */
function phone_format( $content, $post_id, $attributes, $context ) {
	/*
	Do here my computation, and get the phone meta for this post. Apply custom
	formatting, icons, links, etc.
	....
	*/

	return $content;
}