Wordpress 3.5:升级后自定义图库损坏

时间:2013-01-30 17:59:35

标签: wordpress gallery wordpress-3.5

是的,我读过slevin's post,但我很难做出正面或反面,所以......

EDITED&更新如下

我认为我离我更近了,但我不确定...现在该页面会返回整个媒体库中包含的所有图像,而不是附在此特定帖子库中的图像。它正确地格式化,内容上方的图像较大,内容下方的缩略图以及正确包装中的所有内容,但该帖子上只附加了3个图像。

Page url:http://www.vintagepowertrain.com/lkjdkfljdklfj/

这是我现在的代码:

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' => '', 
'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;
    preg_match('/\[gallery.*ids=.(.*).\]/', $post_content, $ids);
    $attachment_ids = explode(",", $ids[1]);
    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++;
    }

}
} 

0 个答案:

没有答案