首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >为什么我的<?php the_post_thumbnail();?>不能在我的wordpress页面上显示任何图片?

问为什么我的<?php the_post_thumbnail();?>不能在我的wordpress页面上显示任何图片?
EN

Stack Overflow用户
提问于 2014-04-24 20:25:30
回答 3查看 3.8K关注 0票数 1

我的代码是

代码语言:javascript
复制
<?php
// Template Name: homepage
get_header(); ?>
    <div id="content" class="full-width">

<?php 
    query_posts(array( 
        'post_type' => 'avada_portfolio',
        'showposts' => 2 
    ) );  
?>
<?php while (have_posts()) : the_post(); ?>
        <h2><a href="<?php the_permalink() ?>"><?php the_title(); ?></a></h2>


    <img src=" <?php the_post_thumbnail('medium'); ?>">
        <p><?php echo get_the_excerpt(); ?></p>
 <?php
    endwhile; //resetting the page loop
    wp_reset_query(); //resetting the page query
    ?>


<h1 class="entry-title"><?php the_title(); ?></h1> <!-- Page Title -->
    <?php
    // TO SHOW THE PAGE CONTENTS
    while ( have_posts() ) : the_post(); ?> <!--Because the_content() works only inside a WP Loop -->
        <div class="entry-content-page">
            <?php the_content(); ?> <!-- Page Content -->
        </div><!-- .entry-content-page -->

    <?php
    endwhile; //resetting the page loop
    wp_reset_query(); //resetting the page query
    ?>

<?php get_footer(); ?>

我已经将<?php add_theme_support( 'post-thumbnails' ); ?>添加到函数中,但是它只在我的主页上显示了一个损坏的图像:(

我的所有图片都被上传到我的wordpress网站上,并被设置为自定义帖子中的特色图片!

谢谢

EN

回答 3

Stack Overflow用户

发布于 2014-04-24 20:40:27

the_post_thumbnail('medium')此函数将返回带有特征图像的img tag。

所以你可以通过以下两种方式获取图片:

代码语言:javascript
复制
<img src=" <?php echo wp_get_attachment_url(get_post_thumbnail_id( $post->ID ), 'medium' ); ?>">

或仅此函数:- <?php the_post_thumbnail('medium'); ?>

希望这能对你有所帮助。

票数 2
EN

Stack Overflow用户

发布于 2014-04-24 20:36:39

在图片标签外写下"the_post_thumbnail('medium');“

如下所示:

代码语言:javascript
复制
<?php while (have_posts()) : the_post(); ?>
    <h2><a href="<?php the_permalink() ?>"><?php the_title(); ?></a></h2>

    <?php the_post_thumbnail('medium'); ?>
    <p><?php echo get_the_excerpt(); ?></p>

<?php
    endwhile; //resetting the page loop
    wp_reset_query(); //resetting the page query
?>
票数 0
EN

Stack Overflow用户

发布于 2017-04-05 16:13:53

代码语言:javascript
复制
<img src=" <?php the_post_thumbnail('medium'); ?>">

这在<img src="">中不起作用。对我来说,这是可行的:

代码语言:javascript
复制
<img src=" <?php echo wp_get_attachment_url(get_post_thumbnail_id( get_the_ID() ), 'thumbnail' ); ?>" class="media-object" style="width:73px; height:73px">
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/23268822

复制
相关文章

相似问题

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