Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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
    
please post the full code of the template. if there is a featured image, then your code is using two html link tags. –  Michael Jan 30 '13 at 0:19

1 Answer 1

You 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

share|improve this answer
    
and what about the double html link tag? –  Michael Jan 30 '13 at 0:20
    
Thanks for the answer and the help. Michael, there is no featured image, i edit my post and i put the code. @WP Themes this part of code doesn't work. –  MikeD Jan 30 '13 at 0:32
    
@Michael, you have right. I didn't enable the Featured Image. Now works. But now i want to exclude the Featured Image (post_thumbnail) from single-portfolio.php. When hyperlink with post and redirect to single-portfolio.php.i don't want to show the post_thumbnail. How can i do that? –  MikeD Jan 30 '13 at 15:14
    
@MikeD - possibly start a new question; and post the code of single-portfolio.php –  Michael Jan 30 '13 at 17:37
    
@Michael thanks. I have already done. –  MikeD Jan 30 '13 at 18:15

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.