【问题标题】:Fetch an array of photos from wordpress gallery从 wordpress 库中获取一组照片
【发布时间】:2012-04-07 21:06:01
【问题描述】:

你知道是否有任何插件或教程描述了如何做到这一点?非常感谢任何帮助,因为我不太擅长 PHP。

我想在 Wordpress 页面上添加照片并将其作为标准图库粘贴到帖子内容中,然后我想避免显示图库,但我感兴趣的是在该图库中获取一组照片,然后遍历它。

它有什么用?我正在开发一个网站http://www.rasterbyte.com/,我想将这些图像用作背景幻灯片(按左/右键更改图片)。目前图像具有固定路径,我希望它们为每个页面自定义。

非常感谢您的任何建议。

【问题讨论】:

    标签: wordpress gallery


    【解决方案1】:

    嗨,Maciek Simm,

    据我了解您的问题,您在帖子中有图片,并且您想在后台显示。

    您可以设置主页类别有 5 个带有特色图片的帖子。

    获取具体帖子图片

    <?php $args = array(
        'width' => null,
        'height' => null,
        'css' => '',
        'parent_id' => '',
        'post_id' => '',
        'filename' => '',
        'return_html' => true       
    ); ?>
    

    或者对于more info

    同时检查How to: Get the first image from the post and display it

    function catch_that_image() {
      global $post, $posts;
      $first_img = '';
      ob_start();
      ob_end_clean();
      $output = preg_match_all('/<img.+src=[\'"]([^\'"]+)[\'"].*>/i', $post->post_content, $matches);
      $first_img = $matches [1] [0];
    
      if(empty($first_img)){ //Defines a default image
        $first_img = "/images/default.jpg";
      }
      return $first_img;
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多