๐ File Manager
๐ Edit File: post-navigation-link.php
<?php /** * Server-side rendering of the `core/post-navigation-link` block. * * @package WordPress */ /** * Renders the `core/post-navigation-link` block on the server. * * @since 5.9.0 * * @param array $attributes Block attributes. * @param string $content Block default content. * * @return string Returns the next or previous post link that is adjacent to the current post. */ function render_block_core_post_navigation_link( $attributes, $content ) { if ( ! is_singular() ) { return ''; } // Get the navigation type to show the proper link. Available options are `next|previous`. $navigation_type = isset( $attributes['type'] ) ? $attributes['type'] : 'next'; // Allow only `next` and `previous` in `$navigation_type`. if ( ! in_array( $navigation_type, array( 'next', 'previous' ), true ) ) { return ''; } $classes = "post-navigation-link-$navigation_type"; if ( isset( $attributes['textAlign'] ) ) { $classes .= " has-text-align-{$attributes['textAlign']}"; } $wrapper_attributes = get_block_wrapper_attributes( array( 'class' => $classes, ) ); // Set default values. $format = '%link'; $link = 'next' === $navigation_type ? _x( 'Next', 'label for next post link' ) : _x( 'Previous', 'label for previous post link' ); $label = ''; // Only use hardcoded values here, otherwise we need to add escaping where these values are used. $arrow_map = array( 'none' => '', 'arrow' => array( 'next' => 'โ', 'previous' => 'โ', ), 'chevron' => array( 'next' => 'ยป', 'previous' => 'ยซ', ), ); // If a custom label is provided, make this a link. // `$label` is used to prepend the provided label, if we want to show the page title as well. if ( isset( $attributes['label'] ) && ! empty( $attributes['label'] ) ) { $label = "{$attributes['label']}"; $link = $label; } // If we want to also show the page title, make the page title a link and prepend the label. if ( isset( $attributes['showTitle'] ) && $attributes['showTitle'] ) { /* * If the label link option is not enabled but there is a custom label, * display the custom label as text before the linked title. */ if ( ! $attributes['linkLabel'] ) { if ( $label ) { $format = '<span class="post-navigation-link__label">' . wp_kses_post( $label ) . '</span> %link'; } $link = '%title'; } elseif ( isset( $attributes['linkLabel'] ) && $attributes['linkLabel'] ) { // If the label link option is enabled and there is a custom label, display it before the title. if ( $label ) { $link = '<span class="post-navigation-link__label">' . wp_kses_post( $label ) . '</span> <span class="post-navigation-link__title">%title</span>'; } else { /* * If the label link option is enabled and there is no custom label, * add a colon between the label and the post title. */ $label = 'next' === $navigation_type ? _x( 'Next:', 'label before the title of the next post' ) : _x( 'Previous:', 'label before the title of the previous post' ); $link = sprintf( '<span class="post-navigation-link__label">%1$s</span> <span class="post-navigation-link__title">%2$s</span>', wp_kses_post( $label ), '%title' ); } } } // Display arrows. if ( isset( $attributes['arrow'] ) && 'none' !== $attributes['arrow'] && isset( $arrow_map[ $attributes['arrow'] ] ) ) { $arrow = $arrow_map[ $attributes['arrow'] ][ $navigation_type ]; if ( 'next' === $navigation_type ) { $format = '%link<span class="wp-block-post-navigation-link__arrow-next is-arrow-' . $attributes['arrow'] . '" aria-hidden="true">' . $arrow . '</span>'; } else { $format = '<span class="wp-block-post-navigation-link__arrow-previous is-arrow-' . $attributes['arrow'] . '" aria-hidden="true">' . $arrow . '</span>%link'; } } /* * The dynamic portion of the function name, `$navigation_type`, * Refers to the type of adjacency, 'next' or 'previous'. * * @see https://developer.wordpress.org/reference/functions/get_previous_post_link/ * @see https://developer.wordpress.org/reference/functions/get_next_post_link/ */ $get_link_function = "get_{$navigation_type}_post_link"; if ( ! empty( $attributes['taxonomy'] ) ) { $content = $get_link_function( $format, $link, true, '', $attributes['taxonomy'] ); } else { $content = $get_link_function( $format, $link ); } return sprintf( '<div %1$s>%2$s</div>', $wrapper_attributes, $content ); } /** * Registers the `core/post-navigation-link` block on the server. * * @since 5.9.0 */ function register_block_core_post_navigation_link() { register_block_type_from_metadata( __DIR__ . '/post-navigation-link', array( 'render_callback' => 'render_block_core_post_navigation_link', ) ); } add_action( 'init', 'register_block_core_post_navigation_link' );
Cancel
Type
Item Name
Actions
๐
..
๐
archives
โ๏ธ
๐
audio
โ๏ธ
๐
avatar
โ๏ธ
๐
block
โ๏ธ
๐
button
โ๏ธ
๐
buttons
โ๏ธ
๐
calendar
โ๏ธ
๐
categories
โ๏ธ
๐
code
โ๏ธ
๐
column
โ๏ธ
๐
columns
โ๏ธ
๐
comment-author-name
โ๏ธ
๐
comment-content
โ๏ธ
๐
comment-date
โ๏ธ
๐
comment-edit-link
โ๏ธ
๐
comment-reply-link
โ๏ธ
๐
comment-template
โ๏ธ
๐
comments
โ๏ธ
๐
comments-pagination
โ๏ธ
๐
comments-pagination-next
โ๏ธ
๐
comments-pagination-numbers
โ๏ธ
๐
comments-pagination-previous
โ๏ธ
๐
comments-title
โ๏ธ
๐
cover
โ๏ธ
๐
details
โ๏ธ
๐
embed
โ๏ธ
๐
file
โ๏ธ
๐
footnotes
โ๏ธ
๐
freeform
โ๏ธ
๐
gallery
โ๏ธ
๐
group
โ๏ธ
๐
heading
โ๏ธ
๐
home-link
โ๏ธ
๐
html
โ๏ธ
๐
image
โ๏ธ
๐
latest-comments
โ๏ธ
๐
latest-posts
โ๏ธ
๐
legacy-widget
โ๏ธ
๐
list
โ๏ธ
๐
list-item
โ๏ธ
๐
loginout
โ๏ธ
๐
media-text
โ๏ธ
๐
missing
โ๏ธ
๐
more
โ๏ธ
๐
navigation
โ๏ธ
๐
navigation-link
โ๏ธ
๐
navigation-submenu
โ๏ธ
๐
nextpage
โ๏ธ
๐
page-list
โ๏ธ
๐
page-list-item
โ๏ธ
๐
paragraph
โ๏ธ
๐
pattern
โ๏ธ
๐
post-author
โ๏ธ
๐
post-author-biography
โ๏ธ
๐
post-author-name
โ๏ธ
๐
post-comments-form
โ๏ธ
๐
post-content
โ๏ธ
๐
post-date
โ๏ธ
๐
post-excerpt
โ๏ธ
๐
post-featured-image
โ๏ธ
๐
post-navigation-link
โ๏ธ
๐
post-template
โ๏ธ
๐
post-terms
โ๏ธ
๐
post-title
โ๏ธ
๐
preformatted
โ๏ธ
๐
pullquote
โ๏ธ
๐
query
โ๏ธ
๐
query-no-results
โ๏ธ
๐
query-pagination
โ๏ธ
๐
query-pagination-next
โ๏ธ
๐
query-pagination-numbers
โ๏ธ
๐
query-pagination-previous
โ๏ธ
๐
query-title
โ๏ธ
๐
quote
โ๏ธ
๐
read-more
โ๏ธ
๐
rss
โ๏ธ
๐
search
โ๏ธ
๐
separator
โ๏ธ
๐
shortcode
โ๏ธ
๐
site-logo
โ๏ธ
๐
site-tagline
โ๏ธ
๐
site-title
โ๏ธ
๐
social-link
โ๏ธ
๐
social-links
โ๏ธ
๐
spacer
โ๏ธ
๐
table
โ๏ธ
๐
tag-cloud
โ๏ธ
๐
template-part
โ๏ธ
๐
term-description
โ๏ธ
๐
text-columns
โ๏ธ
๐
verse
โ๏ธ
๐
video
โ๏ธ
๐
widget-group
โ๏ธ
๐
archives.php
โ๏ธ
๐
๐
avatar.php
โ๏ธ
๐
๐
block.php
โ๏ธ
๐
๐
blocks-json.php
โ๏ธ
๐
๐
button.php
โ๏ธ
๐
๐
calendar.php
โ๏ธ
๐
๐
categories.php
โ๏ธ
๐
๐
comment-author-name.php
โ๏ธ
๐
๐
comment-content.php
โ๏ธ
๐
๐
comment-date.php
โ๏ธ
๐
๐
comment-edit-link.php
โ๏ธ
๐
๐
comment-reply-link.php
โ๏ธ
๐
๐
comment-template.php
โ๏ธ
๐
๐
comments-pagination-next.php
โ๏ธ
๐
๐
comments-pagination-numbers.php
โ๏ธ
๐
๐
comments-pagination-previous.php
โ๏ธ
๐
๐
comments-pagination.php
โ๏ธ
๐
๐
comments-title.php
โ๏ธ
๐
๐
comments.php
โ๏ธ
๐
๐
cover.php
โ๏ธ
๐
๐
file.php
โ๏ธ
๐
๐
footnotes.php
โ๏ธ
๐
๐
gallery.php
โ๏ธ
๐
๐
heading.php
โ๏ธ
๐
๐
home-link.php
โ๏ธ
๐
๐
image.php
โ๏ธ
๐
๐
index.php
โ๏ธ
๐
๐
latest-comments.php
โ๏ธ
๐
๐
latest-posts.php
โ๏ธ
๐
๐
legacy-widget.php
โ๏ธ
๐
๐
list.php
โ๏ธ
๐
๐
loginout.php
โ๏ธ
๐
๐
media-text.php
โ๏ธ
๐
๐
navigation-link.php
โ๏ธ
๐
๐
navigation-submenu.php
โ๏ธ
๐
๐
navigation.php
โ๏ธ
๐
๐
page-list-item.php
โ๏ธ
๐
๐
page-list.php
โ๏ธ
๐
๐
pattern.php
โ๏ธ
๐
๐
post-author-biography.php
โ๏ธ
๐
๐
post-author-name.php
โ๏ธ
๐
๐
post-author.php
โ๏ธ
๐
๐
post-comments-form.php
โ๏ธ
๐
๐
post-content.php
โ๏ธ
๐
๐
post-date.php
โ๏ธ
๐
๐
post-excerpt.php
โ๏ธ
๐
๐
post-featured-image.php
โ๏ธ
๐
๐
post-navigation-link.php
โ๏ธ
๐
๐
post-template.php
โ๏ธ
๐
๐
post-terms.php
โ๏ธ
๐
๐
post-title.php
โ๏ธ
๐
๐
query-no-results.php
โ๏ธ
๐
๐
query-pagination-next.php
โ๏ธ
๐
๐
query-pagination-numbers.php
โ๏ธ
๐
๐
query-pagination-previous.php
โ๏ธ
๐
๐
query-pagination.php
โ๏ธ
๐
๐
query-title.php
โ๏ธ
๐
๐
query.php
โ๏ธ
๐
๐
read-more.php
โ๏ธ
๐
๐
require-dynamic-blocks.php
โ๏ธ
๐
๐
require-static-blocks.php
โ๏ธ
๐
๐
rss.php
โ๏ธ
๐
๐
search.php
โ๏ธ
๐
๐
shortcode.php
โ๏ธ
๐
๐
site-logo.php
โ๏ธ
๐
๐
site-tagline.php
โ๏ธ
๐
๐
site-title.php
โ๏ธ
๐
๐
social-link.php
โ๏ธ
๐
๐
tag-cloud.php
โ๏ธ
๐
๐
template-part.php
โ๏ธ
๐
๐
term-description.php
โ๏ธ
๐
๐
widget-group.php
โ๏ธ
๐