Home Forums Plugin Support WP User Frontend Pro Problems with displaying file uploads…

This topic is: resolved

This topic contains 9 replies, has 2 voices, and was last updated by  paperweight 5 years, 11 months ago.

Viewing 10 posts - 1 through 10 (of 10 total)
  • Author
    Posts
  • #4416

    paperweight
    Participant
    Post count: 122

    I have 2 problems with file upload displays:

    1) I am trying to show the file upload links on the Post page. I followed the instructions and added “file_uploads” to the code here, but it still does not show on my Post pages. Any idea why?

    <?php
    $images = get_post_meta( $post->ID, 'file_uploads' );
     
    if ( $images ) {
        foreach ( $images as $attachment_id ) {
            $thumb = wp_get_attachment_image( $attachment_id, 'thumbnail' );
            $full_size = wp_get_attachment_url( $attachment_id );
     
            printf( '<a href="%s">%s</a>', $full_size, $thumb );
        }
    }
    ?>

    2) Also, I would like to have a small icon of a PDF or DOC next to each download link so the user knows if it is a PDF or DOC file. Is there a way to check the filetype and output a different pdf.jpeg or doc.jpeg?

    #4429

    Tareq Hasan
    Keymaster
    Post count: 2831

    1. Check if you are getting the posts ID by using $post->ID, there might be some plugin or your theme can cause problems.

    2. As attachment ID's are stored for each upload and you get the attachment ID in that foreach loop, you can check the mime type in this way.

    #4432

    paperweight
    Participant
    Post count: 122

    1) I also have images uploaded for a Post, and that code above works fine when using the correct mey_key_name for the image field. However for the file uploads they are not showing. When you say I should use $post->ID you mean what? That seems to already be in the code, right?

    2) Ah, great thanks~

    #4435

    Tareq Hasan
    Keymaster
    Post count: 2831

    $post->ID is the current posts post ID. so if you get the post id correctly (<?php echo $post->ID; ?>), that means it should work fine. As you've said you are getting images correctly, that means files should work correctly too. They work in exact same way. Do you see the meta key values in the admin area correctly? If yes, I don't see any reason why it shouldn't work.

    #4441

    paperweight
    Participant
    Post count: 122

    Ok, I got it working 50%. I changed the code to the following:

    <?php
    $files = get_post_meta( $post->ID, 'file_uploads' );
    if ( $images ) {
        foreach ( $files as $attachment_id ) {
            $thumb = wp_get_attachment_link( $id, 'array(32,32)' , false, false, 'My link text' );
            $full_size = wp_get_attachment_url( $attachment_id );
     
            printf( '<a href="%s">%s</a>', $full_size, $thumb );
        }
      }
    ?>

    Most importantly, I changed the wp_get_attachment_image to wp_get_attachment_link, so there are now more arguments that need to be added.

    However, the “My link text” does not display. Instead, it says “Missing Attachment” and then a link to the correct attachment.

    So, it is now correctly pointing to the correct attachment, but the linked text is incorrect. Any idea why it is saying “Missing Attachment”?

    #4442

    Tareq Hasan
    Keymaster
    Post count: 2831

    I am not sure, but the quote around array(32,32) will not be there for sure.

    #4451

    paperweight
    Participant
    Post count: 122

    Yes, I removed and added the quotes around that a few times with other changes too but the Missing Attachment text always shows.

    WordPress says here http://codex.wordpress.org/Function_Reference/the_attachment_link that the Missing Attachment will display if an attachment can't be found…. but I do have an attachment and that Missing Attachment text accurately links to that file. Very weird and I'm unclear how to fix this…

    #4473

    Tareq Hasan
    Keymaster
    Post count: 2831

    So it's actually displaying the image, but it's showing the missing attachment text? Are you sure $files = get_post_meta( $post->ID, 'file_uploads' ); returns any file list? Try printing it like this: print_r($files); and see if the upload ids are there.

    #4478

    paperweight
    Participant
    Post count: 122

    I have found a 75% solution and still working on it. I will post to this thread as soon as I get closer to 100% 😉

    #4524

    paperweight
    Participant
    Post count: 122

    ok so here is the code I am using now. It is about 85% to where I need it to be, but I can;t figure out anymore:

    <?php  if((get_post_meta( $post->ID, 'file_uploads', true ))) { ?>
    <?php
    $files = get_post_meta( $post->ID, 'file_uploads' );
    if ( $files ) {
        foreach ( $files as $attachment_id ) {
            $thumb = wp_get_attachment_link( $id, array(32,32) , false, true, 'My link text' );
            $full_size = wp_get_attachment_url( $attachment_id );
     
            printf( '<a href="%s"><strong>DOWNLOAD FILE</strong></a>', $full_size, $thumb );
        }
      }
    ?>
    <?php } ?>

    The array(32,32) seems useless so far and I can't get it to display an icon to display a PDF image if the attachment is a PDF or a doc image if attachment is doc, etc. But the good news is it does display correctly the text “DOWNLOAD FILE” with the correct link to the attached file 🙂

    I have a feeling some of my code above is useless, but it sort of works so far~

Viewing 10 posts - 1 through 10 (of 10 total)

The topic ‘Problems with displaying file uploads…’ is closed to new replies.