Personal Reputation2018-08-212019-02-01https://www.workengo.it/wp-content/uploads/2020/05/new-logo.pngWorkengo.ithttps://www.workengo.it/wp-content/uploads/2020/05/new-logo.png200px200px
/**
* Template part for Similar Posts module located in single.php. views/blog/components
*
* @author Artbees
* @package jupiter/views
* @since 5.1.0
* @since 5.9.1 Removed Clear & Bold style if condition.
*/
global $post, $mk_options;
if ($mk_options['enable_single_related_posts'] == 'true' && get_post_meta($post->ID, '_disable_related_posts', true) != 'false') :
$backup = $post;
$tags = wp_get_post_tags($post->ID);
$tagIDs = array();
$related_post_found = false;
$layout = get_post_meta($post->ID, '_layout', true);
$layout = !empty($layout) ? $layout : 'full';
$layout = ($layout == 'default') ? $mk_options['single_layout'] : $layout;
if ($layout == 'full') {
$showposts = 4;
$width = ($mk_options['grid_width'] / 4) - 30;
$height = ($mk_options['grid_width'] / 4) - 80;
$column_css = 'four-cols';
}
else {
$showposts = 3;
$width = (($mk_options['content_width'] / 100) * $mk_options['grid_width']) / 3;
$height = ((($mk_options['content_width'] / 100) * $mk_options['grid_width']) / 3) - 40;
$column_css = 'three-cols';
}
if (!function_exists('mk_similar_posts_html')) {
function mk_similar_posts_html($title, $width, $height, $column_css, $query) {
$output = '';
$output.= '' . esc_html( $title ) . '
';
$output.= '';
while ($query->have_posts()) {
$query->the_post();
$output.= '';
}
$output.= '
';
$output.= '';
echo $output;
}
}
if ($tags) {
$tagcount = count($tags);
for ($i = 0; $i < $tagcount; $i++) {
$tagIDs[$i] = $tags[$i]->term_id;
}
$related = new WP_Query(array(
'tag__in' => $tagIDs,
'post__not_in' => array(
$post->ID
) ,
'showposts' => $showposts,
'ignore_sticky_posts' => 1
));
$output = '';
if ($related->have_posts()) {
$related_post_found = true;
mk_similar_posts_html( esc_html__( 'Articoli Correlati', 'mk_framework' ) , $width, $height, $column_css, $related );
}
$post = $backup;
}
if (!$related_post_found) {
$recent = new WP_Query(array(
'showposts' => $showposts,
'nopaging' => 0,
'post__not_in' => array(
$post->ID
),
'post_status' => 'publish',
'ignore_sticky_posts' => 1
));
$output = '';
if ($recent->have_posts()) {
$related_post_found = true;
mk_similar_posts_html( esc_html__( 'Ultimi Articoli', 'mk_framework' ) , $width, $height, $column_css, $recent );
}
}
wp_reset_postdata();
echo $output;
endif;