【问题标题】:How to get orginal size(link) images using in gallery wordpress?如何在图库 wordpress 中使用原始大小(链接)图像?
【发布时间】:2017-02-06 15:49:39
【问题描述】:

我正在用纯 JS 创建滑块。我的 Slider 有 2 个主要元素。 1.微缩图片列表(图库wordpress); 2. div 元素。当我们点击缩影时,我们会看到更大的画面。

它正在工作。但我有一个问题。画质很差。这样做的结果是引用 src 到微型。如何从帖子库使用的数据库中获取链接?

我使用了 get_the_post_gallery()。

【问题讨论】:

标签: wordpress


【解决方案1】:
$images = get_post_gallery( $post, false );
$ids = explode( ",", $images['ids'] );

foreach( $ids as $id ) {
   $link = wp_get_attachment_url( $id );
// Now you can do something here to pass the URL to your js
} 

https://codex.wordpress.org/Function_Reference/get_post_gallery
这是一种获取完整尺寸图像的 URL 的方法。我没有测试代码,但它应该是好的。如果您有问题,请告诉我。我会提供一种将 URL 传递给您的 JS 的方法,但您没有提供任何代码,所以这很难。

【讨论】:

  • 明天我退房。
【解决方案2】:

是的,它的作品:)。 我很少像这样修改代码:

if (get_post_gallery()){
     initSliderAPI();
     $gallery = get_post_gallery( $post, false );
      $ids = explode( ",", $gallery['ids'] );
      $linkList = Array();
      $counter = 0;
      foreach( $ids as $id ) {
      $link = wp_get_attachment_url( $id );
      $linkList[$counter] = $link;
      $counter++;
    }

我在 nodeList 中获得链接“

  • " 图像,当 API 启动时,方法 createEvents 为每个节点创建事件。下一步当我得到 eventTarget let node = this.domImageSliderGroup.item(this.nodeID); let image = new Image (300); image.src = node.firstChild.src;
  • 【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-11-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-08-20
      相关资源
      最近更新 更多