简体   繁体   English

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

[英]Wordpress PHP custom field - Individual links for slideshow

The following is code for a Wordpress slideshow. 以下是Wordpress幻灯片显示的代码。 The images are added through custom fields. 通过自定义字段添加图像。 I would like to be able to add a different link (or no link) to each of the slides. 我希望能够为每个幻灯片添加一个不同的链接(或没有链接)。 The current code is below, any tips on how to do that? 下面是当前代码,有关该操作的任何提示? The theme is quite old. 主题很老。

Thank you!! 谢谢!!

<?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>

You need to add another custom field for the link of each image , where you are insering the header image in post_meta you need to add the custom field say, img_link also , then you can do it this way . 您需要为每个图像的链接添加另一个自定义字段,在post_meta中插入标头图像的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;


    ?>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM