我的代码是
<?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网站上,并被设置为自定义帖子中的特色图片!
谢谢
发布于 2014-04-24 20:40:27
the_post_thumbnail('medium')此函数将返回带有特征图像的img tag。
所以你可以通过以下两种方式获取图片:
<img src=" <?php echo wp_get_attachment_url(get_post_thumbnail_id( $post->ID ), 'medium' ); ?>">或仅此函数:- <?php the_post_thumbnail('medium'); ?>
希望这能对你有所帮助。
发布于 2014-04-24 20:36:39
在图片标签外写下"the_post_thumbnail('medium');“
如下所示:
<?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
?>发布于 2017-04-05 16:13:53
<img src=" <?php the_post_thumbnail('medium'); ?>">这在<img src="">中不起作用。对我来说,这是可行的:
<img src=" <?php echo wp_get_attachment_url(get_post_thumbnail_id( get_the_ID() ), 'thumbnail' ); ?>" class="media-object" style="width:73px; height:73px">https://stackoverflow.com/questions/23268822
复制相似问题