Add a captions to integrated FlexSlider on Wordpress Organictheme.

江枫思渺然 提交于 2019-12-12 00:44:09

问题


Would like to add a caption to FlexSlider, which is integrated into a purchased Wordpress Organictheme. I believe the slideshow page code must be modified and though I have found some similar issues here, I have not figured out (after many hours and failed attempts) where and what exactly to add to the existing code. Seems like captions should be a no-brainer! Seems like they should somehow be included within the

  • tags??? Would REALLY APPRECIATE some help. html, but NOT php literate. THANK YOU!

    The code needs to go somewhere in here:

                <div class="flexslider">
    
                    <ul class="slides">
    
                        <?php $data = array(
                            'post_parent'       => $post->ID,
                            'post_type'         => 'attachment',
                            'post_mime_type'    => 'image',
                            'order'             => 'ASC',
                            'orderby'           => 'menu_order',
                            'numberposts'       => -1
                        ); ?>
    
                        <?php 
                        $images = get_posts($data); foreach( $images as $image ) { 
                            $imageurl = wp_get_attachment_url($image->ID);              echo '<li><img src="'.$imageurl.'"  /></li>' . "\n"; 
                        } ?>
    
                    </ul>
    
                </div>
    

    回答1:


    You were very close, indeed.

    I'll answer this in case someone else needs it. The two missing bits of code are:

    <p class="flex-caption"><?php echo $caption; ?></p>
    

    ... required by flexslider to display the captions, and

    $caption = $image->post_excerpt;
    

    ... to actually obtain the captions. New code would be:

            <div class="flexslider">
    
                <ul class="slides">
    
                    <?php $data = array(
                        'post_parent'       => $post->ID,
                        'post_type'         => 'attachment',
                        'post_mime_type'    => 'image',
                        'order'             => 'ASC',
                        'orderby'           => 'menu_order',
                        'numberposts'       => -1
                    ); ?>
    
                    <?php 
                    $images = get_posts($data);
                    foreach( $images as $image ) { 
                        $imageurl = wp_get_attachment_url($image->ID);
                        $caption = $image->post_excerpt;
                        echo '<li><img src="'.$imageurl.'"  /><p class="flex-caption">'.$caption.'</p></li>' . "\n";
                    } ?>
    
                </ul>
    
            </div>
    


    来源:https://stackoverflow.com/questions/16579510/add-a-captions-to-integrated-flexslider-on-wordpress-organictheme

    易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
    该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!