结束循环...基于POST ID的特色图像变量

时间:2018-01-30 作者:g_ange

我是Wordpress模板和php开发的新手。我正在制作一个模板,从多个帖子中在一个页面上绘制多个帖子缩略图。我遇到的问题是,特色图片都是一样的,继承了第一篇文章的图片。下面是我的代码-如果您能帮助我在每篇帖子中包含自己的特色图片,我将不胜感激:)

 <div class="col-lg-2 text-center">
              <div class="soap-container tire-clean">
                 <?php
                $post_id = 35;
                $queried_post = get_post($post_id);
                $featured_img_url = get_the_post_thumbnail_url($post->ID, \'full\'); 
                ?>
              <a href="#" data-toggle="modal" data-target="#tireModal"><img width="100%" src="<?php echo get_the_post_thumbnail(\'35\', \'full\'); ?>"></a>
              <a href="#" data-toggle="modal" data-target="#tireModal"><h3><?php echo $queried_post->post_title; ?></h3></a>
              </div> 
            </div>


            <div class="col-lg-2 text-center">
              <div class="soap-container tire-clean">
                 <?php
                $post_id = 37;
                $queried_post = get_post($post_id);
                $featured_img_url = get_the_post_thumbnail_url($post->ID, \'full\'); 
                ?>
              <a href="#" data-toggle="modal" data-target="#tireModal"><img width="100%" src="<?php echo get_the_post_thumbnail(\'37\', \'full\'); ?>"></a>
              <a href="#" data-toggle="modal" data-target="#tireModal"><h3><?php echo $queried_post->post_title; ?></h3></a>
              </div> 
            </div>
            <div class="col-lg-2 text-center">
              <div class="soap-container mega-foam">
                 <?php
                $post_id = 39;
                $queried_post = get_post($post_id);
                $featured_img_url = get_the_post_thumbnail_url($post->ID, \'full\'); 
                ?>
              <a href="#" data-toggle="modal" data-target="#foamModal"><img width="100%" src="<?php echo get_the_post_thumbnail(\'39\', \'full\'); ?>"></a>
              <a href="#" data-toggle="modal" data-target="#foamModal"><h3><?php echo $queried_post->post_title; ?></h3></a>
              </div> 
            </div>

1 个回复
最合适的回答,由SO网友:Michael 整理而成

try using:

        $featured_img_url = get_the_post_thumbnail_url($queried_post->ID, \'full\'); 
结束

相关推荐

Remove <p></p> after images

我对<p></p> 出现在my之后的标记<img....>. 以下是我在本地主机上查看生成的页面时显示的内容。。。<img src=\"/wp-content/themes/wunderful/assets/images/feedback-danielle.png\" alt=\"Danielle Johnson Deal Town FC Treasurer\"> <p></p> 请注意随机生成的<p>&