Banzi Posts
'post_status' => 'publish',
'posts_per_page' => $posts_per_page,
'orderby' => array(
'menu_order' => 'ASC',
'date' => 'DESC',
),
'order' => 'ASC',
);
if (!empty($exclude_current) && $exclude_current == '1') {
$current_id = get_queried_object_id();
if ($current_id) {
$args['post__not_in'] = array($current_id);
}
}
$query = new WP_Query($args);
if ($query->have_posts()) {
while ($query->have_posts()) {
$query->the_post();
$post_id = get_the_ID();
$thumbnail = get_field('thumbnail', $post_id);
$title = trim((string) get_field('title', $post_id));
$link = trim((string) get_field('link', $post_id));
/*
* Fall back to the native WordPress title when
* the ACF title field has not been entered.
*/
if ($title === '') {
$title = get_the_title($post_id);
}
/*
* Fall back to the custom post permalink when
* the ACF link field has not been entered.
*/
if ($link === '') {
$link = get_permalink($post_id);
}
$image_url = '';
$image_alt = $title;
/*
* Supports all ACF image return formats:
* Image Array, Image ID, or Image URL.
*/
if (is_array($thumbnail)) {
$image_url = !empty($thumbnail['sizes']['large'])
? $thumbnail['sizes']['large']
: ($thumbnail['url'] ?? '');
if (!empty($thumbnail['alt'])) {
$image_alt = $thumbnail['alt'];
}
} elseif (is_numeric($thumbnail)) {
$image_url = wp_get_attachment_image_url(
(int) $thumbnail,
'large'
);
$attachment_alt = get_post_meta(
(int) $thumbnail,
'_wp_attachment_image_alt',
true
);
if (!empty($attachment_alt)) {
$image_alt = $attachment_alt;
}
} elseif (is_string($thumbnail)) {
$image_url = $thumbnail;
}
/*
* Determine whether the link should open in
* a new tab. External URLs open in a new tab.
*/
$link_host = wp_parse_url($link, PHP_URL_HOST);
$site_host = wp_parse_url(home_url(), PHP_URL_HOST);
$is_external = (
!empty($link_host) &&
!empty($site_host) &&
strtolower($link_host) !== strtolower($site_host)
);
$link_target = $is_external ? '_blank' : '_self';
$link_rel = $is_external ? 'noopener noreferrer' : '';
?>





