Wordpress PHP自定义字段-幻灯片的个人链接


Wordpress PHP custom field - Individual links for slideshow

下面是Wordpress幻灯片的代码。图像是通过自定义字段添加的。我希望能够添加不同的链接(或没有链接)到每个幻灯片。当前的代码如下,关于如何做到这一点有什么建议吗?

谢谢! !

<?php
        /* reading the custom field value 'headerImage'
            * muliple 'headerImage' image will cause js transition
            * if no 'headerImage' found then display default-header.jpg
            */
        $headerImages = get_post_meta($post->ID, "headerImage", false);
        ?>
            <!--photo starts-->
        <div class="photo noprint">
            <div id="fx" class="big-image">
                <?php if( is_array( $headerImages ) && count( $headerImages ) > 0 ): for( $i=0; $i<count($headerImages); $i++ ): ?>
                    <img src="<?php echo $headerImages[$i]; ?>" alt=""<?php if($i != 0) echo ' style="display:none;"'; ?> />
                    <?php endfor; else: ?>
                        <img src="<?php bloginfo('template_url'); ?>/images/default-header.jpg" alt="" />
                <?php endif; ?>
            </div>
        </div>

你需要为每个图像的链接添加另一个自定义字段,在post_meta中插入标题图像的地方,你需要添加自定义字段,比如img_link,然后你可以这样做。

    <?php
    $headerImages = get_post_meta($post->ID, "headerImage", false);
    $img_link = get_post_meta($post->ID, "img_link", false);

    if( is_array( $headerImages ) && count( $headerImages ) > 0 
    && is_array( $img_link ) && count( $img_link ) > 0 ):

    for( $i=0; $i < count($headerImages) ,  $i < count ($img_link ) ; $i++ ): 
    ?>
    <a href = "<?php echo $img_link[$i]; ?>" >
    <img src="<?php echo $headerImages[$i]; ?>" 
    alt=""<?php if($i != 0) echo ' style="display:none;"'; ?> />
    </a>
    <?php endfor; else: ?>
    <img src="<?php bloginfo('template_url'); ?>/images/default-header.jpg" alt="" />
    <?php endif;

    ?>