在自定义公文包图像下显示WordPress图像标题

时间:2014-12-23 作者:user2623187

我在这里得到了这个定制的portfolio php文件:

http://pastebin.com/B4ZgdQZT

或者你可以在问题的末尾看到它。。。

问题是我无法显示图像标题。我尝试了不同的方法,但都没能成功。当我希望公文包页面上的每个图像都显示其确切标题时,所有图像始终显示第一个附加图像的相同标题。与第一个连接的不一样。

图像的平铺在第57行

有什么建议吗?

<?php
if($grid_gallery == "1 column"){
    $portfolio_container = "container-24";
    $portfolio_category = true;
    $portfolio_img_w = 1000;
    $portfolio_img_h = 300;
} elseif ($grid_gallery == "2 columns") {
    $portfolio_container = "container-12";
    $portfolio_category = true;
    $portfolio_img_w = 500;
    $portfolio_img_h = 300;
} elseif ($grid_gallery == "3 columns") {
    $portfolio_container = "container-8";
    $portfolio_small_tag = "-small";
    $portfolio_img_w = 500;
    $portfolio_img_h = 300;
} elseif ($grid_gallery == "4 columns") {
    $portfolio_container = "container-6";
    $portfolio_small_tag = "-small";
    $portfolio_img_w = 193;
    $portfolio_img_h = 112;
}

$gallery_images = json_decode(htmlspecialchars_decode(get_post_meta(get_the_ID(), \'glocal_company_gallery\', true)));
$count_arr = count((array)$gallery_images);
if(is_object($gallery_images) && $count_arr >= 1) :
    $i = 1;
    $k = 1;
    foreach($gallery_images as $_img) { if($k == $i) { $main = wp_get_attachment_image_src($_img); } $k++; }
    $k = 1;
    foreach($gallery_images as $_img) :

        $image = wp_get_attachment_image_src($_img, \'full\');   ?>
        <div class="portfolio-container <?php echo $portfolio_container; ?>">
            <div class="portfolio-listing<?php echo $portfolio_small_tag; ?> block">
                <div class="portfolio-image">

               <a href="<?php echo $image[0] ?>" class="portfolio-enlarge">

                <img src="<?php echo vt_resizer($image[0], $portfolio_img_w, $portfolio_img_h); ?>" alt="<?php the_title() ?>" title="<?php the_title(); ?>" />

                </a>

                </div>
                <?php if($portfolio_category == true): ?>
                <div class="portfolio-description development clearfix">
                    <div class="portfolio-title-category">
                        <div class="portfolio-title"><?php the_title() ?></div>
                        <div class="portfolio-category text-colorful"><?php echo __(\'Portfolio\',\'glocal_site\'); ?></div>
                    </div>
                    <a href="<?php echo $image[0] ?>" class="portfolio-enlarge" target="_blank"></a>
                </div>
                <?php else: ?>
                <div class="portfolio-title">
                <a href="<?php echo $image[0] ?>" class="portfolio-enlarge">

                TITLE GOES HERE

                </a>
                </div>

                <?php endif; ?>
            </div>
        </div>
        <?php $k++;
    endforeach;
endif;

1 个回复
SO网友:Ashok Kumar Nath

而不是the_title() 尝试以下操作:echo get_the_title($_img). 它应该只在foreach循环内工作。

结束

相关推荐

the_title not working

我正在使用the_title() 显示自定义帖子类型的标题,但它不起作用;标题不显示。get_header(); $wp_query = new WP_Query(); $wp_query -> query(\'post_type=press&showposts=20\'); while ($wp_query->have_posts()) : $wp_query->the_post(); ?> <div cla