WordPress.org

Ready to get started?Download WordPress

Forums

How do I put the title attribute into index thumbnails? (5 posts)

  1. fjavier
    Member
    Posted 1 year ago #

    How do I put the title attribute into the thumbnails in my index page? I have the thumbnails linking to the posts and I'm using the following code to generate the thumbnails:

    function dp_attachment_image($postid=0, $size='thumbnail', $attributes='',$echo=1,
    $beforeimg='',$afterimg='',$numberposts=1) {
    if ($postid<1) $postid = get_the_ID();
    if ($images = get_children(array(
    'post_parent' => $postid,
    'post_type' => 'attachment',
    'numberposts' => $numberposts,
    'post_mime_type' => 'image',)))
    $link = get_permalink($postid);
    foreach($images as $image) {
    $img = $beforeimg;
    $img .= "<a href='$link'>";
    $attachment=wp_get_attachment_image_src($image->ID, $size);
    $img .= "<img src='{$attachment[0]}' $attributes /></a>";
    $img .= $afterimg;
    if ($echo) {
    echo $img;
    } else {
    return $img; }
    } }
    
    <?php dp_attachment_image($post->ID,'thumbnail','width="300px"', 1,'<div class="post-thumbnail">','</div>', 1); ?>

    Thanks in advance.

  2. Santosh
    Member
    Posted 1 year ago #

    you have to make change in template file not in this function because it is just returning image.

  3. fjavier
    Member
    Posted 1 year ago #

    Hi santosh, the last line goes in the template. Thanks

  4. Santosh
    Member
    Posted 1 year ago #

    <?php dp_attachment_image($post->ID,'thumbnail','width="300px"', 1,'<div class="post-thumbnail">','</div>', 1); ?>

    I never seen this line. i thought it is a function.

  5. fjavier
    Member
    Posted 1 year ago #

    Correct, that is the code for the thumbnails in template, I have the item's title (permalink) itself linking to the posts too and it has the title attribute set like this:

    <a href="<?php the_permalink(); ?>" title="<?php printf( __('Read %s', 'ew'), the_title_attribute('echo=0') ); ?>" rel="bookmark"><?php the_title(); ?></a>

    I don't know how to do the trick for the thumbnails.

Topic Closed

This topic has been closed to new replies.

About this Topic