WordPress: output 3 records with check viewable (виведення 3х записів, з перевіркою поточного запису)

Last update: 22 Квітня, 2023

Category: WordPress

<?php echo $post_id = get_the_ID(); ?>
<?php
    $posts = get_posts ("category=7&orderby=date&numberposts=4");
    $n = 0;
    echo '<ul class="">';
        if ($posts) : foreach ($posts as $post) : setup_postdata ($post);
            $temp_post_id = get_the_ID();
            if ( ( $temp_post_id != $post_id ) && ( $n < 3 ) ) {
                echo ' <li class=""><a href="'.get_the_permalink().'"><img src="'.get_the_post_thumbnail_url().'">'.get_the_title().'</a></li>';
                $n++;
            }
        endforeach;
    wp_reset_postdata();
    echo '</ul>';
    endif;
?>