0

This is driving me slightly demented. It's taken me a few hours to work out how to do this and I thought I finally had it, but the link text will only echo the file name and not the link text I want it to. Easy solution is re-name the file to "View Price List", but what if someone further down the line adds a new file and doesn't realise the name has to be the same as the button link text.

I would like the link text to be the same no matter what the name of the attached file is i.e. "Download Price List" or "Pobierz cennik".

<?php if( $post->ID == 38) {?>
     <?php $default_strings = array(
            'price_text' => array(
            'en' => 'Download Price List',
            'pl' => 'Pobierz cennik'
            )
        );?>

     <?php
     global $post;
     $args = array(
            'numberposts' => -1,
            'order'=> 'ASC',
            'post_mime_type' => 'application/msword, application/vnd.ms-excel, application/pdf',
            'post_parent' => $post->ID,
            'post_status' => 'any',
            'post_type' => 'attachment'
            );

    $attachments = get_posts($args);
            if ($attachments) { ?>
            <?php
            foreach ($attachments as $attachment) {?>

            <a class="button big brand-1" <?php echo the_attachment_link($attachment->ID, false); ?>>
            <?php echo $default_strings['price_text'][ $lang ]; ?>
            </a>

            <?php } 
           }?>

          <?php }?>
0

I've changed the button to:

    <a class="button big brand-1" a href="<?php echo wp_get_attachment_url($attachment->ID, false); ?>">
            <?php echo $default_strings['price_text'][ $lang ]; ?>
    </a>

a href is added around the wp_get_attachment_url rather than using the_attachment_link which contains the whole link.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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