【问题标题】:Automatic in page gallery wordpress在页面画廊 wordpress 中自动
【发布时间】:2011-03-09 18:42:38
【问题描述】:

我正在为我的客户寻找一个简单的图片库。

我需要能够从帖子或页面中上传多张图片,并将图片自动添加到页面并设置样式。

我可以解决这个http://wordpress.org/support/topic/post-image-4

这听起来与我正在寻找的相似,但我似乎无法让它正常工作。

有人知道我该怎么做吗?

【问题讨论】:

    标签: wordpress upload gallery


    【解决方案1】:

    想通了。

    只需要将这个添加到functions.php中

    <?php
    function postimage($size=medium,$num=1,$lighbox=1) {
        if ( $images = get_children(array(
            'post_parent' => get_the_ID(),
            'post_type' => 'attachment',
            'numberposts' => $num,
            'order' => 'ASC',
            'orderby' => 'ID',
            'post_mime_type' => 'image',)))
        {
            foreach( $images as $image ) {
                $attachmenturl=wp_get_attachment_url($image->ID);
                $attachmentimage=wp_get_attachment_image($image->ID, $size );
                $img_title = $image->post_title;
                $img_desc = $image->post_excerpt;
                if ($size != "full"){
                    echo '<a href="'.$attachmenturl.'" rel="lightbox" title="'.$img_desc.'">'.$attachmentimage.'</a>'.$img_title.'';
                } else {
                    echo '<img src="'.$attachmenturl.'">';
                }
            }
        } else {
            echo "No Image";
        }
    }
    ?>
    

    然后将其添加到帖子页面(在我的情况下为 single.php)

    <?php postimage('thumbnail'); ?>
    

    现在在特定帖子中上传的所有图片都会自动添加。

    【讨论】:

      【解决方案2】:

      【讨论】:

      • 我以前用过这个插件。它作为图片库非常有用,但是我需要能够在直接编辑页面/帖子的同时上传图片。
      猜你喜欢
      • 1970-01-01
      • 2017-05-17
      • 2016-03-18
      • 2016-11-25
      • 1970-01-01
      • 1970-01-01
      • 2011-11-27
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多