[英]wordpress 5 empty site when i load pictures from media library
I am currently trying to implement the carousel from bootstrap 4 in wordpress.我目前正在尝试从 wordpress 中的引导程序 4 实现轮播。 unfortunately i got that when i load the pictures from wordpress media library i get empty site.
不幸的是,当我从 wordpress 媒体库加载图片时,我得到了空站点。 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我需要以编程方式在 wordpress 中插入帖子.. 图像已上传但未附加.. 当我从媒体库加载图像时,但当我从计算机的文件夹中加载时
I exchanged that get_the_ID() with get_post() now working我用 get_post() 交换了 get_the_ID() 现在可以工作了
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.