добавить thumbnails для базового виджета Post Navigation Elementor
Wed Jan 05 2022 08:38:04 GMT+0000 (Coordinated Universal Time)
Saved by
@mastaklance
/**
* Thumbnails option on Post Navigation Elementor widget
*/
add_filter('previous_post_link', 'sydney_child_post_nav_thumbnail', 20, 5 );
add_filter('next_post_link', 'sydney_child_post_nav_thumbnail', 20, 5 );
function sydney_child_post_nav_thumbnail($output, $format, $link, $post, $adjacent) {
if( !$output ) {
return;
}
$divclass = '';
switch ($adjacent) {
case 'next':
$divclass = 'custom-nav nav-next';
break;
case 'previous':
$divclass = 'custom-nav nav-previous';
break;
default:
break;
}
$arrow_prev = '';
$arrow_next = '';
if( 'next' == $adjacent ) {
$arrow_next = '<span>⟶</span>';
}
if( 'previous' == $adjacent ) {
$arrow_prev = '<span>⟵</span>';
}
$rel = $adjacent;
$thumb = get_the_post_thumbnail($post->ID, array( 100, 100));
$title = '<div class="'.$divclass.'">' . $arrow_prev . $post->post_title . $arrow_next . '</div>';
$class = '';
if( !empty($thumb) ) {
$class = 'post-nav-has-thumbnail';
}
$string = '<a href="' . get_permalink( $post->ID ) . '" rel="' . $rel . '" class="'.$class.'">' . $thumb;
$inlink = str_replace( '%title', $title, $link );
$inlink = $string . $inlink . '</a>';
$output = str_replace( '%link', $inlink, $format );
if( !$post->ID ) {
return;
}
return $output;
}
content_copyCOPY
/* elementor post navigation + thumbnails */
#single-product-pagination .elementor-post-navigation {
height: 160px;
}
#single-product-pagination .elementor-post-navigation__next {
position: absolute;
margin-top: 82px;
}
#single-product-pagination .elementor-post-navigation__link {
width: 100%;
}
#single-product-pagination img {
max-width: 70px;
margin-right: 20px;
}
#single-product-pagination .elementor-post-navigation__next a {
float: left;
}
#single-product-pagination span.elementor-post-navigation__link__next {
text-align: left;
}
#single-product-pagination span.post-navigation__prev--label, #single-product-pagination span.post-navigation__next--label {
padding: 5px;
}
#single-product-pagination span.post-navigation__prev--title, #single-product-pagination span.post-navigation__next--title {
padding-left: 5px;
}
Comments