我只是在我的網站中手動設置同位素,然后在 get_terms 和 get_ther_terms 條件的幫助下動態它,這里是完整的代碼 <div class="main_page"><div class="portfolio_section"> <div class="controls"> <button type="button" class="control" data-filter="all">All</button> <?php $cat_list = get_terms('filters'); foreach ($cat_list as $cat) : ?> <button type="button" class="control" data-filter=".<?php echo $cat->slug;?>"><?php echo $cat->name; ?></button> <?php endforeach; ?> </div> <div class="container pasresnt"> <?php $mixitup = new WP_Query(array( 'post_type' => 'portfolio', 'posts_per_page' => -1, )); ?> <?php while ($mixitup->have_posts()) : $mixitup->the_post() ; ?><div class="mix <?php $cat_slug = get_the_terms($post->ID, 'filters'); foreach ($cat_slug as $cat_sl) { echo $cat_sl->slug; } ?>"> <a href="<?php the_post_thumbnail('portfolio-small'); ?>" target="_blank"><?php the_post_thumbnail('portfolio-small'); ?> </a> </div> <?php endwhile; ?> <div class="mix green"> <a href="<?php echo get_template_directory_uri(); ?>/img/mahi.jpg"><img src="<?php echo get_template_directory_uri(); ?>/img/mahi.jpg"alt=""></a></div></div> </div> </div>這是正常靜態圖像彈出窗口中的亮點,此代碼正確顯示 <a href="<?php echo get_template_directory_uri(); ?>/img/mahi.jpg"><img src="<?php echo get_template_directory_uri(); ?>/img/mahi.jpg"alt=""></a>但在動態中,此圖像彈出窗口對我不起作用。最后一個靜態圖像作為示例,工作完美,但這行代碼是圖像來自投資組合自定義帖子選項,此彈出窗口不起作用<a href="<?php echo $for_img; ?>" target="_blank"><?php the_post_thumbnail('portfolio-small'); ?> </a>`
1 回答

弒天下
TA貢獻1818條經驗 獲得超8個贊
您正在the_post_thumbnail使用href. 這會輸出 html 來顯示圖像,但您只想將 URL 放入href鏈接的屬性中,因此請改用get_the_post_thumbnail_url()。
所以代替這個:
<a href="<?php the_post_thumbnail('portfolio-small'); ?>" target="_blank"><?php the_post_thumbnail('portfolio-small'); ?> </a>
你應該使用這個:
<a href="<?php echo get_the_post_thumbnail_url(get_the_ID(), 'portfolio-small'); ?>" target="_blank">
<?php the_post_thumbnail('portfolio-small'); ?>
</a>
- 1 回答
- 0 關注
- 137 瀏覽
添加回答
舉報
0/150
提交
取消