【发布时间】:2011-03-09 18:42:38
【问题描述】:
我正在为我的客户寻找一个简单的图片库。
我需要能够从帖子或页面中上传多张图片,并将图片自动添加到页面并设置样式。
我可以解决这个http://wordpress.org/support/topic/post-image-4
这听起来与我正在寻找的相似,但我似乎无法让它正常工作。
有人知道我该怎么做吗?
【问题讨论】:
我正在为我的客户寻找一个简单的图片库。
我需要能够从帖子或页面中上传多张图片,并将图片自动添加到页面并设置样式。
我可以解决这个http://wordpress.org/support/topic/post-image-4
这听起来与我正在寻找的相似,但我似乎无法让它正常工作。
有人知道我该怎么做吗?
【问题讨论】:
想通了。
只需要将这个添加到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'); ?>
现在在特定帖子中上传的所有图片都会自动添加。
【讨论】:
试试 nextgen 画廊 :) http://wordpress.org/extend/plugins/nextgen-gallery/
【讨论】: