I am trying to link to an image in a loop in wordpress but it is not displaying properly. The image will be set so its not being pulled from the article. Here is the code where I am making an error.

echo '<img alt="'.the_title(); <?php echo "src=/"". bloginfo('template_directory').'/images/green/newsImg1.png " />';

And here is the full code to anyone who needs it.

<?php query_posts('cat=3&showposts=2'); ?>

			<?php if (have_posts()) : ?>

			<?php while (have_posts()) : the_post(); ?>

            <div class="newsPreview mb15">

            <?php
                  { 				    
                          echo "<img alt=\"".the_title(). "\" src="\".bloginfo('template_directory')." />";
			            echo '<img alt="'.the_title(); <?php echo "src=/"". bloginfo('template_directory').'/images/green/newsImg1.png " />';

			        }

			?>
            <span class="previewTitle"><a href="<?php the_permalink() ?>" title=""><?php the_title(); ?></a></span>

			<?php the_excerpt('');?>

            </div>
			<?php endwhile; else : ?>

			<?php endif; ?>

Thank you in advance for your help.

    Use get_bloginfo() instead. It works exactly as bloginfo(), except it returns the value whereas bloginfo() simply just echoes it out.

    Also, the_title() should be the_title(false). By default the_title (and other "the_" functions) echo out the value rather than return it. the_title(false) returns the title so you can use it in your echo statement.

      Bonesnap;10991031 wrote:

      Use get_bloginfo() instead. It works exactly as bloginfo(), except it returns the value whereas bloginfo() simply just echoes it out.
      .

      That code is just returning the blog name but not the link to theme template directory so I will have to see if I can pass some more values inside the get_blog info.

      Thanks at least I am close now.

        Well you would still write get_bloginfo('template_directory')...

          I managed to separate the HTML and php properly. Thanks for the help. Here is the final code

          <a href="<?php the_permalink() ?>"> 
             <img src="<?php bloginfo('template_url'); ?>/images/green/newsImg1.png" alt="<?php the_title(false);?>" class="newsImg"/></a>
             <span class="previewTitle"><a href="<?php the_permalink() ?>" title=""><?php the_title(); ?></a></span> 
            Write a Reply...