php – 如何在某个div中插入图库的每个图像? WordPress的

发布时间:2022-04-30 发布网站:脚本宝典
脚本宝典收集整理的这篇文章主要介绍了php – 如何在某个div中插入图库的每个图像? WordPress的脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。
@H_301_2@
我正在尝试 reproduce this Masonry来展示一个画廊.我为此创建了一个CPT. “CPT – 画廊”.

首先,我想到创建一个自定义帖子类型来一起发布所有图像.

我的CPT:

—>>>标题<<<< ---
—>>>图像认 – 缩略图<<< ---
—>>>强效<<<<
—>>>图像<<< —
—>>>图像<<< —

前三个部分(标题,图像认和内容)是基础.准备好了.

之后,我考虑使用自定义元数据并添加每个图像URL.但是,通过URL添加URL并不是直观的,对于用户来说,无论是新手还是高级,都可以为用户提供更多功能.此外,金额会有所不同,图片可以是1,可能是5可能是10等等.

我看到有一个plugin for WordPress,但插件不是全,当我将插件的CSS设置为全宽时,Mansory在视口大小调整中获得了几个错误.

注意到插件代码功能,我在每篇文章中看到,插件使用自己的wordpress编辑器库.它采用生成的短代码(在the_content();内部)并在Mansory类中显示图像.

我正在尝试这样做,但没有成功.

无论如何,我想做什么?

– >抓住wordpress图库的短代码并在我的砌体的div中显示每个图像< - 逻辑示例:
画廊的简码:

我拍摄每张图片并在循环中显示.

实际例子:

在这里,我用砌体的div执行循环.

<?PHP
  $args = array( 'post_tyPE' => 'gallery','showposts' => 1 );
  $wp_query = new WP_Query($args);
  if(have_posts()):
    while ($wp_query -> have_posts()) : $wp_query -> the_post();
?>

<div class="ITem">
  <figure style="margin: 0px !important" itemPRop="associatedMedia" itemscope itemtype="http://schema.org/ImageObject">
      <a href="<?PHP IMAGE 1 OF GALLERY Wp; ?>" itemprop="contentUrl" data-size="1800x1200" data-index="0">
          <img src="<?PHP IMAGE 1 OF GALLERY WP; ?>" class="image" itemprop="thumbnail" alt="">
      </a>
  </figure>
</div>

随着循环将出现在库中的所有图像.

<div class="item">
  <figure style="margin: 0px !important" itemprop="associatedMedia" itemscope itemtype="http://schema.org/ImageObject">
      <a href="<?PHP IMAGE 2 OF GALLERY WP; ?>" itemprop="contentUrl" data-size="1800x1200" data-index="0">
          <img src="<?PHP IMAGE 2 OF GALLERY WP; ?>" class="image" itemprop="thumbnail" alt="">
      </a>
  </figure>
</div>

<div class="item">
  <figure style="margin: 0px !important" itemprop="associatedMedia" itemscope itemtype="http://schema.org/ImageObject">
      <a href="<?PHP IMAGE 3 OF GALLERY WP; ?>" itemprop="contentUrl" data-size="1800x1200" data-index="0">
          <img src="<?PHP IMAGE 3 OF GALLERY WP; ?>" class="image" itemprop="thumbnail" alt="">
      </a>
  </figure>
</div>

 and so on.....

我怎么能这样做?

解决方法

你快到了.您只需要获取并循环浏览图库图像.这样的事情对你有用.
参考这里: https://codex.wordpress.org/Function_Reference/get_post_gallery_images

<?PHP
global $post;
$gallery = get_post_gallery_images( $post );

foreach( $gallery as $image_url ) {
?>
<div class="item">
  <figure style="margin: 0px !important" itemprop="associatedMedia" itemscope itemtype="http://schema.org/ImageObject">
      <a href="<?PHP echo $image_url ?>" itemprop="contentUrl" data-size="1800x1200" data-index="0">
          <img src="<?PHP echo $image_url ?>" class="image" itemprop="thumbnail" alt="">
      </a>
  </figure>
</div>
<?PHP 
}
?>
@H_301_2@

脚本宝典总结

以上是脚本宝典为你收集整理的php – 如何在某个div中插入图库的每个图像? WordPress的全部内容,希望文章能够帮你解决php – 如何在某个div中插入图库的每个图像? WordPress的所遇到的问题。

如果觉得脚本宝典网站内容还不错,欢迎将脚本宝典推荐好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。