在图像库的alt标记中显示自定义字段值

时间:2016-03-13 10:44:41

标签: php jquery wordpress

我正在尝试在图片库的“alt”标记中显示自定义字段值,但如果我使用'alt' => '<?php echo ($workinfo); ?>',则不会显示,除非我使用简单的字词。以下是我的代码:

PHP

 <ul class="templatemo-project-gallery" >
            <?php
             $query = new WP_Query( array('showposts' => 10, 'post_type' => 'portfolio') );
             while ( $query->have_posts() ) : $query->the_post();

            global $post;
            $meta = get_post_meta( $post->ID );
            $workinfo      = isset( $meta['work_description'][0] )  ? filter_var( $meta['work_description'][0],  FILTER_SANITIZE_STRING ) : '';

            ?>

            <li class="col-lg-3 col-md-3 col-sm-3  gallery gallery-creative" >
                <a class="fancybox" data-fancybox-group="gallery" title="<?php the_title(); ?>" href="<?php echo wp_get_attachment_url( get_post_thumbnail_id($post->ID) ); ?>">
                    <div class="templatemo-project-box">
                        <?php the_post_thumbnail('full', array('class' => 'img-responsive', 'alt' => '<?php echo $workinfo; ?>' )); ?>
                        <span class="fa fa-plus projectplus"></span>
                        <div class="project-overlay">
                            <h5><?php the_title(); ?></h5>
                        </div>
                    </div>
                </a>
            </li>

            <?php endwhile; ?>
            <?php wp_reset_postdata(); ?>


        </ul>

JS SCRIPT for FANCYBOX

jQuery(function($) {
$(".fancybox").fancybox({
    padding : 0,
    autoResize: true,
    beforeShow: function () {
      this.title = $(this.element).attr('title');
      this.title = '<h4>' + this.title + '</h4>' + '<p>' + $(this.element).parent().find('img').attr('alt') + '</p>';
    },
    helpers : {
      title : { type: 'inside' },
    }
});

});

在图库中,标题部分显示为空白。如何显示$ workinfo值?

0 个答案:

没有答案