I am currently trying to implement the carousel from bootstrap 4 in wordpress. unfortunately i got that when i load the pictures from wordpress media library i get empty site. where is the lack? this is the test code
<?php
function image_slider_get_attachment( $num = 1 ){
$output = '';
if( has_post_thumbnail() && $num == 1 ):
$output = wp_get_attachment_url( get_post_thumbnail_id( get_the_ID() ) );
else:
$attachments = get_posts( array(
'post_type' => 'attachment',
'posts_per_page' => $num,
'post_parent' => get_the_ID()
) );
if( $attachments && $num == 1 ):
foreach ( $attachments as $attachment ):
$output = wp_get_attachment_url( $attachment->ID );
endforeach;
elseif( $attachments && $num > 1 ):
$output = $attachments;
endif;
wp_reset_postdata();
endif;
return $output;
}
?>
<article id="post-<?php the_ID(); ?>" <?php post_class( 'format-gallery' ); ?>>
<header class="entry-header text-center">
<?php if( image_slider_get_attachment() ):
$attachments = image_slider_get_attachment(5);
// var_dump($attachments);
?>
<div id="post-gallery-<?php the_ID(); ?>" class="carousel slide carousel-thumb" data-ride="carousel">
<div class="carousel-inner" role="listbox" >
<?php
$i = 0;
foreach( $attachments as $attachment ):
$active = ( $i == 0 ? ' active' : '' );
?>
<div class="carousel-item <?php echo $active; ?> background-image standard-featured" style="background-image: url( <?php echo wp_get_attachment_url( $attachment->ID ); ?> );"></div>
<?php $i++; endforeach; ?>
</div><!-- .carousel-inner -->
<a class="left carousel-control-prev" href="#post-gallery-<?php the_ID(); ?>" role="button" data-slide="prev">
<span class="carousel-control-prev-icon" aria-hidden="true"></span>
<span class="sr-only">Previous</span>
</a>
<a class="right carousel-control-next" href="#post-gallery-<?php the_ID(); ?>" role="button" data-slide="next">
<span class="carousel-control-next-icon" aria-hidden="true"></span>
<span class="sr-only">Next</span>
</a>
</div><!-- .carousel -->
<?php endif; ?>
</header>
</article>
I need to insert post programatically in wordpress.. image is uploaded but not attached.. when i load the images from the media library, but when i load from the folder from the computer thats work