编码图库,PHP获得WP'特色'图像

时间:2013-07-12 22:42:58

标签: php wordpress

我目前正在使用yoxview图片库。 (www.yoxigen.com/yoxview/)但这并不重要。我目前在一个小的启动主页上编码,我在 Wordpress 安装前设置。我想在这里做的是允许通过Yoxview的图像库以原子方式抓取和放大拉动Wordpress帖子分配的“精选”图像集。我假设我需要一些 PHP 代替href=""src="",但我不确定是什么。基本上,只是希望图库动态操作并使用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特色图片'?

1 个答案:

答案 0 :(得分: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' );