Code
Explorer
You are a developer and looking for Shopware projects?
Apply Now!
the_excerpt example
$content
=
get_the_content
(
)
;
// If there is no quote or pullquote print the content.
if
(
has_block
(
'core/quote',
$content
)
)
{
twenty_twenty_one_print_first_instance_of_block
(
'core/quote',
$content
)
;
}
elseif
(
has_block
(
'core/pullquote',
$content
)
)
{
twenty_twenty_one_print_first_instance_of_block
(
'core/pullquote',
$content
)
;
}
else
{
the_excerpt
(
)
;
}
<?php /** * Show the excerpt. * * @link https://developer.wordpress.org/themes/basics/template-hierarchy/ * * @package WordPress * @subpackage Twenty_Twenty_One * @since Twenty Twenty-One 1.0 */
the_excerpt
(
)
;
$content
=
get_the_content
(
)
;
if
(
has_block
(
'core/video',
$content
)
)
{
twenty_twenty_one_print_first_instance_of_block
(
'core/video',
$content
)
;
}
elseif
(
has_block
(
'core/embed',
$content
)
)
{
twenty_twenty_one_print_first_instance_of_block
(
'core/embed',
$content
)
;
}
else
{
twenty_twenty_one_print_first_instance_of_block
(
'core-embed/*',
$content
)
;
}
// Add the excerpt.
the_excerpt
(
)
;
// Print the 1st gallery found.
if
(
has_block
(
'core/gallery',
get_the_content
(
)
)
)
{
twenty_twenty_one_print_first_instance_of_block
(
'core/gallery',
get_the_content
(
)
)
;
}
the_excerpt
(
)
;
$content
=
get_the_content
(
)
;
if
(
has_block
(
'core/audio',
$content
)
)
{
twenty_twenty_one_print_first_instance_of_block
(
'core/audio',
$content
)
;
}
elseif
(
has_block
(
'core/embed',
$content
)
)
{
twenty_twenty_one_print_first_instance_of_block
(
'core/embed',
$content
)
;
}
else
{
twenty_twenty_one_print_first_instance_of_block
(
'core-embed/*',
$content
)
;
}
// Add the excerpt.
the_excerpt
(
)
;
// If there is no featured-image, print the first image block found.
if
(
!
twenty_twenty_one_can_show_post_thumbnail
(
)
&&
has_block
(
'core/image',
get_the_content
(
)
)
)
{
twenty_twenty_one_print_first_instance_of_block
(
'core/image',
get_the_content
(
)
)
;
}
the_excerpt
(
)
;
// If there are paragraph blocks, print up to two. // Otherwise this is legacy content, so print the excerpt.
if
(
has_block
(
'core/paragraph',
get_the_content
(
)
)
)
{
twenty_twenty_one_print_first_instance_of_block
(
'core/paragraph',
get_the_content
(
)
, 2
)
;
}
else
{
the_excerpt
(
)
;
}