Post Dynamic Part
Displays a post label from a type, meta, term, attribute, a static string, or even a custom PHP filter.
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.
Block name
t2/post-dynamic-part
Attributes
tag
The output wrapper tag, defaultdiv
. Other options: label, span, p, h1 -> h6.source
The output source, defaults to attribute. Other options: object, meta, text, term, filter.prefix
Optional text to be placed in front of the content.suffix
Optional text to be placed after the content.text
A custom static text to be output.target
The target of the selected source. For example: the taxonomy when the term is set as a source.divider
A content divider, default,
.limit
A limit for multiple items, default1
. Other options: 0 - no limit, 2 - two items. This is mostly related to taxonomy terms and post meta output.link
Use or not link when applicable, defaultfalse
. This is mostly related to term and author output, where we might need the links or not, depending on the context where the block is rendered.
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"} /-->
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;
}