我使用了我在3.4中为一个光滑的小自定义库找到的教程,但升级到3.5后,它就不再工作了。我仍在努力学习php,但似乎无法再次使用它,因为我要么出错,要么什么都没有。无论如何,在升级之前,用户所要做的就是点击“添加媒体”,上传他想在帖子中显示的任何图像[在本例中是产品],设置图像的顺序,第一个图像是顶部/全尺寸图像,然后在文本字段中键入他的描述,当他点击“提交”时,将以上所有内容以良好的格式显示出来,如下所示:
single.php
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
x First image attached to post, large size x
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
--------------> Output of content box <--------------
xxxxxxxxxxxxxxxxxxxxxxxxxxxx xxxxxxxxxxxxxxxxxxxxxxxxxxxx
x second image, thumbnail x x third image, thumbnail x
xxxxxxxxxxxxxxxxxxxxxxxxxxxx xxxxxxxxxxxxxxxxxxxxxxxxxxxx
这里是我称之为单曲的地方。php:
<div class="entry-content">
<div id="top-image"><?php wpo_get_images(\'large\',\'1\',\'0\',\'large\',"$post->ID",\'1\',\'feat-img\',\'div\',\'main-thumb\'); ?></div>
<?php the_content(); ?>
<div class="outer-element">
<?php wpo_get_images(\'thumbnail\',\'0\',\'1\',\'large\',"$post->ID",\'1\',\'bot-thumbs\',\'div\',\'inner-element\'); ?>
</div>
</div>
这是我的函数。php:
// Add the ability to use post thumbnails if it isn\'t already enabled.
// Not required. Use only of you want to have more than the large,
// medium or thumbnail options WP uses by default.
if ( function_exists( \'add_image_size\' ) ) add_theme_support( \'post-thumbnails\' );
// Add custom thumbnail sizes to your theme. These sizes will be auto-generated
// by the media manager when adding images to it on a new post.
if ( function_exists( \'add_image_size\' ) ) {
add_image_size( \'t1x1\', 145, 200, true );
add_image_size( \'t2x1\', 307, 200, true );
add_image_size( \'t2x2\', 307, 417, true );
}
///////////////////////////////////////////////
//
// Start WPOutfitters.com Custom Gallery Function
//
//////////////////////////////////////////////
function wpo_get_images($size = \'thumbnail\', $limit = \'0\', $offset = \'0\', $big = \'large\', $post_id = \'$post->ID\', $link = \'1\', $img_class = \'attachment-image\', $wrapper = \'div\', $wrapper_class = \'attachment-image-wrapper\') {
global $post;
$images = get_children( array(\'post_parent\' => $post_id, \'post_status\' => \'inherit\', \'post_type\' => \'attachment\', \'post_mime_type\' => \'image\', \'order\' => \'ASC\', \'orderby\' => \'menu_order ID\') );
if ($images) {
$num_of_images = count($images);
if ($offset > 0) : $start = $offset--; else : $start = 0; endif;
if ($limit > 0) : $stop = $limit+$start; else : $stop = $num_of_images; endif;
$i = 0;
foreach ($images as $attachment_id => $image) {
if ($start <= $i and $i < $stop) {
$img_title = $image->post_title; // title.
$img_description = $image->post_content; // description.
$img_caption = $image->post_excerpt; // caption.
//$img_page = get_permalink($image->ID); // The link to the attachment page.
$img_alt = get_post_meta($attachment_id, \'_wp_attachment_image_alt\', true);
if ($img_alt == \'\') {
$img_alt = $img_title;
}
if ($big == \'large\') {
$big_array = image_downsize( $image->ID, $big );
$img_url = $big_array[0]; // large.
} else {
$img_url = wp_get_attachment_url($image->ID); // url of the full size image.
}
// FIXED to account for non-existant thumb sizes.
$preview_array = image_downsize( $image->ID, $size );
if ($preview_array[3] != \'true\') {
$preview_array = image_downsize( $image->ID, \'thumbnail\' );
$img_preview = $preview_array[0]; // thumbnail or medium image to use for preview.
$img_width = $preview_array[1];
$img_height = $preview_array[2];
} else {
$img_preview = $preview_array[0]; // thumbnail or medium image to use for preview.
$img_width = $preview_array[1];
$img_height = $preview_array[2];
}
// End FIXED to account for non-existant thumb sizes.
///////////////////////////////////////////////////////////
// This is where you\'d create your custom image/link/whatever tag using the variables above.
// This is an example of a basic image tag using this method.
?>
<?php if ($wrapper != \'0\') : ?>
<<?php echo $wrapper; ?> class="<?php echo $wrapper_class; ?>">
<?php endif; ?>
<?php if ($link == \'1\') : ?>
<a href="<?php echo $img_url; ?>" title="<?php echo $img_title; ?>">
<?php endif; ?>
<img class="<?php echo $img_class; ?>" src="<?php echo $img_preview; ?>" alt="<?php echo $img_alt; ?>" title="<?php echo $img_title; ?>" />
<?php if ($link == \'1\') : ?>
</a>
<?php endif; ?>
<?php if ($img_caption != \'\') : ?>
<div class="attachment-caption"><?php echo $img_caption; ?></div>
<?php endif; ?>
<?php if ($img_description != \'\') : ?>
<div class="attachment-description"><?php echo $img_description; ?></div>
<?php endif; ?>
<?php if ($wrapper != \'0\') : ?>
</<?php echo $wrapper; ?>>
<?php endif; ?>
<?php
// End custom image tag. Do not edit below here.
///////////////////////////////////////////////////////////
}
$i++;
}
}
}
如果有人能把我引向正确的方向,甚至能解释一下什么东西坏了,以及任何额外的信息,让我尽可能多地学习,那就太好了!