admin管理员组文章数量:1122832
I am try to insert link to my thumbnail images, the link is hyperlink with post. When i put this code inside the loop then instead of showing the first image, first show the second image (template_url)
<a href="<?php the_permalink() ?>" class="alignnone" title="<?php the_title(); ?>">
<?php if (has_post_thumbnail()) : ?>
<a href="<?php the_permalink(); ?>" title="<?php the_title();?>"><?php the_post_thumbnail(); ?></a>
<?php else : ?>
<img src="<?php bloginfo('template_url'); ?>/images/noimage.jpg" width="213" height="187" alt=""/>
<?php endif; ?>
</a>
The code of the tempate :
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<div <?php post_class() ?> id="post-<?php the_ID(); ?>=">
<div class="item">
<ul>
<li>
<a href="<?php the_permalink() ?>" class="alignnone" title="<?php the_title(); ?>">
<a href="<?php the_permalink(); ?>" title="<?php the_title();?>">
<?php if (has_post_thumbnail()) : ?>
<?php the_post_thumbnail(); ?></a>
<?php else : ?>
<img src="<?php bloginfo('template_url'); ?>/images/noimage.jpg" width="213" height="187" alt=""/>
<?php endif; ?>
</a>
<div id="info">
<div class="title_album"> <strong>Άlbum : </strong> <?php print_custom_field('title_album'); ?><br /> </div>
<div class="number_photos"><strong>Photos : </strong> <?php print_custom_field('Number_photos'); ?><br /> </div>
</div>
</li>
</ul>
</div> <!-- end item -->
</div> <!-- END div class post -->
Even if this part of code, the result is the same..
<?php echo '<a href="', get_permalink(), '">';
if (has_post_thumbnail())
{the_post_thumbnail();}
else {echo'<img src="', get_bloginfo('template_directory'), '/images/noimage.jpg', '" width="213" height="187" alt="thumbnail" />';}
echo '</a>'; ?>
I am try to insert link to my thumbnail images, the link is hyperlink with post. When i put this code inside the loop then instead of showing the first image, first show the second image (template_url)
<a href="<?php the_permalink() ?>" class="alignnone" title="<?php the_title(); ?>">
<?php if (has_post_thumbnail()) : ?>
<a href="<?php the_permalink(); ?>" title="<?php the_title();?>"><?php the_post_thumbnail(); ?></a>
<?php else : ?>
<img src="<?php bloginfo('template_url'); ?>/images/noimage.jpg" width="213" height="187" alt=""/>
<?php endif; ?>
</a>
The code of the tempate :
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<div <?php post_class() ?> id="post-<?php the_ID(); ?>=">
<div class="item">
<ul>
<li>
<a href="<?php the_permalink() ?>" class="alignnone" title="<?php the_title(); ?>">
<a href="<?php the_permalink(); ?>" title="<?php the_title();?>">
<?php if (has_post_thumbnail()) : ?>
<?php the_post_thumbnail(); ?></a>
<?php else : ?>
<img src="<?php bloginfo('template_url'); ?>/images/noimage.jpg" width="213" height="187" alt=""/>
<?php endif; ?>
</a>
<div id="info">
<div class="title_album"> <strong>Άlbum : </strong> <?php print_custom_field('title_album'); ?><br /> </div>
<div class="number_photos"><strong>Photos : </strong> <?php print_custom_field('Number_photos'); ?><br /> </div>
</div>
</li>
</ul>
</div> <!-- end item -->
</div> <!-- END div class post -->
Even if this part of code, the result is the same..
<?php echo '<a href="', get_permalink(), '">';
if (has_post_thumbnail())
{the_post_thumbnail();}
else {echo'<img src="', get_bloginfo('template_directory'), '/images/noimage.jpg', '" width="213" height="187" alt="thumbnail" />';}
echo '</a>'; ?>
Share
Improve this question
edited Jan 30, 2013 at 2:02
asked Jan 30, 2013 at 0:00
user24259user24259
1
- please post the full code of the template. if there is a featured image, then your code is using two html link tags. – Michael Commented Jan 30, 2013 at 0:19
2 Answers
Reset to default 0You may want to change your code to something like this:
<a href="<?php the_permalink() ?>" class="alignnone" title="<?php the_title(); ?>">
<a href="<?php the_permalink(); ?>" title="<?php the_title();?>">
<?php if (has_post_thumbnail()) : ?>
<?php the_post_thumbnail(); ?></a>
<?php else : ?>
<img src="<?php bloginfo('template_url'); ?>/images/noimage.jpg" width="213" height="187" alt=""/>
<?php endif; ?>
</a>
and I assume you've specified a Featured Image for the post thumbnail to show up yes? http://codex.wordpress.org/Post_Thumbnails
You could not use anchor tag inside an another anchor tag, Try like this....
<a href="<?php the_permalink() ?>" class="alignnone" title="<?php the_title(); ?>">
<?php if (has_post_thumbnail()) : ?>
<?php the_post_thumbnail(); ?>
<?php else : ?>
<img src="<?php bloginfo('template_url'); ?>/images/noimage.jpg" width="213" height="187" alt=""/>
<?php endif; ?>
</a>
本文标签: postsInsert link to my thumbnail images
版权声明:本文标题:posts - Insert link to my thumbnail images 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736286830a1927753.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论