在wordpress类别上发布缩略图链接

时间:2013-07-08 19:47:49

标签: wordpress hyperlink thumbnails

我使用此代码在我的类别上显示缩略图:

<?php the_post_thumbnail('thumbnail', array('class' => 'alignleft')); ?>

但我想将它们变成链接。 我试试这段代码:

<?php if ( has_post_thumbnail()) : ?>
<a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>" >
<?php the_post_thumbnail(); ?>
</a>
<?php endif; ?>

但图像右侧不再显示文字,图像太大。

如何解决这个问题? (来源:http://codex.wordpress.org/Function_Reference/the_post_thumbnail

1 个答案:

答案 0 :(得分:2)

试试这个:

<?php $imageClass = array ( 'class' => "alignleft",); ?>
<?php if ( has_post_thumbnail()) : ?>
<a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>" >
<?php the_post_thumbnail('thumbnail', $imageClass); ?>
</a>
<?php endif; ?>