0

我目前正在使用 yoxview 图片库。(www.yoxigen.com/yoxview/) 但这并不重要。我目前在安装Wordpress之前设置的一个小型启动主页上对此进行了编码。我在这里尝试做的是允许通过 Yoxview 的图片库以原子方式抓取和拉取由 Wordpress 帖子分配的“精选”图片集。我假设我需要一些PHP来代替href=""andsrc=""但不确定是什么。本质上,只是希望画廊动态运行并使用 Wordpress 帖子中设置的特色图片作为拇指填充。谁能帮我写这个?干杯。

<div class="thumbnails yoxview">

    <a href="/wp-content/uploads/2013/06/broken-beer-bottle.jpg"><img src="/wp-content/uploads/2013/06/broken-beer-bottle.jpg" alt="First" title="The first image" class="thumb"/></a>

    <a href="/wp-content/uploads/2013/06/29214_116842028347050_6051723_n.jpg"><img src="/wp-content/uploads/2013/06/29214_116842028347050_6051723_n.jpg" alt="" title="The SECOND image" class="thumb" style="max-height: 100px;"/></a> 

    <a href="/wp-content/uploads/2013/07/images.jpg"><img src="/wp-content/uploads/2013/07/images.jpg" alt="" title="The Third image" class="thumb" style="max-height: 100px;"/></a>

    <a href="/wp-content/uploads/2013/07/solocups.jpg"><img src="/wp-content/uploads/2013/07/solocups.jpg" alt="" title="The Third image" class="thumb" style="max-height: 100px;"/></a>

</div> 

可能是更好的改写;如何用 PHP 编写“获取 Wordpress 特色图片”?

4

1 回答 1

0

这是我用来获取单个帖子的特色图片和附加图片的代码:

  $args = array(
    'order' => 'ASC',
    'post_mime_type' => 'image',
    'post_parent' => $post->ID,
    'post_status' => null,
    'post_type' => 'attachment',

  );

  $upload_dir = wp_upload_dir();
  $upload_url = $upload_dir['baseurl'];


  // Get img data
  $attachments    = get_children( $args );
  $images = array();

  foreach($attachments as $attachment) {
    $image_attributes = wp_get_attachment_image_src( $attachment->ID, 'thumbnail' );
    $img['thumb'] = $image_attributes[0];
    $image_attributes = wp_get_attachment_image_src( $attachment->ID, 'large' );
    $img['large'] = $image_attributes[0];
    array_push($images,$img);
  }

  $featured_img = wp_get_attachment_url(get_post_thumbnail_id($post->ID));
  $featured_img_thumb = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID), 'thumbnail' );
于 2013-07-12T22:53:24.657 回答