Support

Account

Forum Replies Created

  • This worked for me and I am able to get the file type extension but now I would like to use an if statement with that extension so I can assign icons to my files based on the file type. So for example, if the filetype equals pdf then I would output a pdf icon. How can I do an if else type of statement using this?

    I tried the following but no luck:

    <?php $attachment_id = get_field('document_upload');
    $url = wp_get_attachment_url( $attachment_id );
    $title = get_the_title( $attachment_id );
    
    // part where to get the filesize
    $filesize = filesize( get_attached_file( $attachment_id ) );
    $filesize = size_format($filesize, 2);
    $path_info = pathinfo( get_attached_file( $attachment_id ) );
    
    // show custom field
    if (get_field('document_upload')): ?>
    
    <?php echo $filesize; ?>
    <?php echo $path_info['extension']; ?>
    
    <?php
    if ($path_info = "pdf") {
        echo "<i class='fa fa-file-pdf-o' aria-hidden='true'></i>";
    } ?>
    
    <?php endif; ?>	

    Not really sure where to go from here. Thanks

  • Figured it out. The code is fine I just had to go into the custom fields admin page and chanage the “Return Value” from image URL to image ID.

  • So none of those solutions worked but I did find something that did. I used the following code and was able to get the image to finally show up.

                                            <?php
    $publisher_photo = get_the_author_meta('user_profile_image');
    $image_src = wp_get_attachment_image_src($publisher_photo);
    echo '<img class="avatar" src="'. $image_src[0] .'" />';
    ?>

    Thank you for your help with this.

  • I did have the return value for image. I also tried your code but am still only getting it to output the image ID. http://s15.postimg.org/q2ycawbwb/Capture.jpg

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