首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >get_the_post_thumbnail()不能在页面模板中工作

get_the_post_thumbnail()不能在页面模板中工作
EN

Stack Overflow用户
提问于 2017-05-15 09:51:00
回答 2查看 267关注 0票数 0

下面的代码放置在一个名为placed web.php的包含文件中:

代码语言:javascript
复制
<?php
                    $args = array( 'numberposts' => '8', 'category_name' => 'web-reference' );
                    $recent_posts = wp_get_recent_posts( $args );
                    foreach( $recent_posts as $recent ){
                        $featured_image = get_the_post_thumbnail();
                        $poveznica = get_field('link-projekta');
                        echo '<figure class="effect-winston">
                        ' . $featured_image . '
                        <figcaption>
                            <h2><a href="' . get_permalink($recent["ID"]) . '">' . $recent["post_title"] . '</a></h2>
                            <p>
                                <a href="' . get_permalink($recent["ID"]) . '"><i class="fa fa-fw fa-list"></i></a>
                                <a href="' . $poveznica . '" target="_blank"><i class="fa fa-fw fa-link"></i></a>
                            </p>
                        </figcaption>           
                    </figure>';
                    }
                    wp_reset_query();
?>

当在index.html中包含文件时,它工作得完美无缺,但是当将它包含在页面模板中时,就会出现问题。代码正确地提取所有信息。但是,图像/缩略图根本不显示。从浏览器检查时没有img标记。有人有办法解决这个问题吗?

谢谢!

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2017-05-15 10:27:38

请试试这个,在缩略图功能中添加了最近的id。

代码语言:javascript
复制
<?php
                    $args = array( 'numberposts' => '8');
                    $recent_posts = wp_get_recent_posts( $args );
                    foreach( $recent_posts as $recent ){
                        $featured_image = get_the_post_thumbnail($recent["ID"]);
                        $poveznica = get_field('link-projekta');
                        echo '<figure class="effect-winston">
                        ' . $featured_image . '
                        <figcaption>
                            <h2><a href="' . get_permalink($recent["ID"]) . '">' . $recent["post_title"] . '</a></h2>
                            <p>
                                <a href="' . get_permalink($recent["ID"]) . '"><i class="fa fa-fw fa-list"></i></a>
                                <a href="' . $poveznica . '" target="_blank"><i class="fa fa-fw fa-link"></i></a>
                            </p>
                        </figcaption>           
                    </figure>';
                    }
                    wp_reset_query();
?>
票数 0
EN

Stack Overflow用户

发布于 2017-05-16 10:12:48

在某些时候,get_the_post_thumbnail()不起作用,直到您传递post的ID,所以在您的例子中foeach循环中,您必须在get_the_post_thumbnail()中传递recentID,所以它看起来像get_the_post_thumbnail(最近的‘ID’),并且您完成了

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/43976350

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档