自动在页面库wordpress

时间:2011-03-09 18:42:39

标签: wordpress upload gallery

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

我需要能够在帖子或页面中上传多个图像,并将图像自动添加到页面中,并进行样式化。

我能够完成这个http://wordpress.org/support/topic/post-image-4

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

有谁知道我怎么能这样做?

2 个答案:

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

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

答案 1 :(得分:0)

相关问题