• jezthomp

    (@jezthomp)


    I have the following showing a link to an uploaded pdf…

    <?php
    					$attachs = get_posts(array(
    					 'post_type' => 'attachment',
    					 'post_parent' => get_the_ID(),
    					 'numberposts' => -1
    					));
    					if (!empty($attachs)) {
    					 foreach ($attachs as $att) {
    					  if (wp_attachment_is_image($att->ID)) continue;
    					  echo '<li>' . wp_get_attachment_link($att->ID) . '</li>';
    
    					 }
    					}
    					?>

    Is it possible to attach a span within the link with some text that appears for each link, like say ‘Download’?

    Looking like this…?

Viewing 8 replies - 1 through 8 (of 8 total)
  • coopersita

    (@coopersita)

    Did you check the documentation:
    http://codex.wordpress.org/Function_Reference/wp_get_attachment_link

    You could have something like:

    echo '<li>' . wp_get_attachment_link($att->ID, '' , false, false, 'Download') . '</li>';

    Thread Starter jezthomp

    (@jezthomp)

    Yeah i tired that but it replaces the existing name of the file, i still need that there, along with the Download text… 🙁

    coopersita

    (@coopersita)

    Just put it twice:

    echo '
    <li>' . wp_get_attachment_link($att->ID) . wp_get_attachment_link($att->ID, '' , false, false, ' - Download') .'</li>
    ';

    It will create the link twice, but it should work.

    Thread Starter jezthomp

    (@jezthomp)

    Ah yes that does work thank you.

    However, how would i go about adding html. i.e putting that ‘download’ text in a <span> tag without it actually physically showing the <span> tag as text?

    coopersita

    (@coopersita)

    echo '
    <li>' . wp_get_attachment_link($att->ID) . wp_get_attachment_link($att->ID, '' , false, false, ' <span> - Download</span>') .'</li>
    ';

    That doesn’t work?

    Thread Starter jezthomp

    (@jezthomp)

    Nope it doesn’t print it as html.

    It literally prints the <span> live front end, rather than putting the ‘download’ in a span element.

    🙁

    coopersita

    (@coopersita)

    How about you use <?php wp_get_attachment_url( $post_id ); ?>instead? :

    echo '
    
    <li>' . wp_get_attachment_link($att->ID) . ' <a href="'.wp_get_attachment_url( $att-ID ).'"><span>Download</span></a></li>
    ';
    Thread Starter jezthomp

    (@jezthomp)

    That correctly puts the span class has html.

    But the link around it is an empty one not the actual link the one above has.

    Odd.

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘Add html (span) to wp_get_attachment_link??’ is closed to new replies.