Viewing 7 replies - 1 through 7 (of 7 total)
  • Is it within the main wordpress loop or is it custom loop

    Thread Starter Steven

    (@spstieng)

    That was quick ??
    I think it’s within a custom loop?

    <?php while (have_posts()) : the_post(); ?>
    (... , my code here)
    <?php endwhile; ?>

    Paste the full code, the_title() should be displaying properly, cant see anything obviously wrong.

    Thread Starter Steven

    (@spstieng)

    <div id="leftcol">
        <?php
          // "Featured articles" (Nyheter) module begins
          query_posts('showposts=3&cat=15'); ?>
          <h3> Nyheter  </h3>
          <?php while (have_posts()) : the_post(); ?>
          <div class="feature">
    
      <?php
    	$basePath = get_option('upload_path') . '/';
    	$permaLink = get_permalink();
    	// this grabs the image filename ffrom image gallery
    	$values = get_post_custom_values("featuredarticleimage");
    
    	// this checks to see if an image file exists
    	if(empty($values[0]))
    	{
    		//Grab url to external image
    		$values = get_post_custom_values("externalthumb");
    		$basePath = '';
    	}
    
    	// If and image has been related, it will be displayed
    	if(!empty($values[0]))
    	{
      	echo '<a href="' . $permaLink . '">';
      	echo '<img src="' . $basePath[0] . $values[0] . '" alt="artikkelbilde" />';
      	echo '</a>';
      }
      ?>
    
          <a href="<?php the_permalink() ?>" rel="bookmark" class="title">
            <?php the_title(); ?>
          </a>
          <p>
            <?php the_content_rss('Les mer','', '', 20); ?>
            <a href="<?php the_permalink() ?>">Les mer</a>.
          </p>
        </div>
        <?php endwhile; ?>
      </div>
      <!--END LEFTCOL-->

    See the line echo ‘<img src=”‘ . $basePath[0] . $values[0] . ‘” alt=”artikkelbilde” />’; ?

    I will replace ‘artikkelbilde’ with the_title() and the new code looks like this:
    echo ‘<img src=”‘ . $basePath[0] . $values[0] . ‘” alt=”‘ . the_title() . ‘” />’;

    You can see the result here.

    Notice the small linked text in front of the headline. This is the ALT text. If you look at the source code, you will see alt=””.

    Your code is generating

    <a href="">Manolo Blahnik blir foreviget<img src="https://i285.photobucket.com/albums/ll59/shoeslove/manolo-blahnik.jpg" alt="" /></a>

    I think you need to user $posts = query_posts(…)

    Thread Starter Steven

    (@spstieng)

    Didn’t quite understand you answer hotkee.
    I am using query_posts()
    query_posts(‘showposts=3&cat=15’);

    Well, I’ve created a workaround. I’ve added a custom fild fot image title and will use this for ALT text.

    Sorry I was talking rubbish in last reply.

    I managed to get the title coming out by using the following

    <img src = "<?php echo $basePath[0].$values[0]; ?>" alt="<?php the_title(); ?>" />

    This is placed outside of the main <?php ?>

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘how to use the_title() in ALT tags’ is closed to new replies.