Support

Account

Home Forums General Issues Images Not Showing Up on Pages

Solved

Images Not Showing Up on Pages

  • Hello. Great plugin that is almost working perfectly. I’ll submit each problem as a separate topic.

    IMAGES NOT SHOWING UP
    Images are not showing up on pages where the template code (from the documentation documentation page http://www.advancedcustomfields.com/resources/field-types/image/ )

    a. this code doesn’t work. nothing shows up:

    <img src="<?php the_field('field_name'); ?>" alt="" />

    b. this code also doesn’t work:

    <?php if( get_field('field_name') ): ?><img src="<?php the_field('field_name'); ?>" alt="" /><?php endif; ?>

    I’ve placed the above code on the author.php template page. All other types of fields are successfully showing up using this code:
    <dt><?php echo $curauth->field_name; ?></dd>

    And on my template pages I have substituted “field_name” for my actual field names. Is there any other code that I should be using?

  • Hi @jimario

    What setting do you have for the return format of the image field?

    If you have set this to ‘Image Array’ or ‘Image ID’, your above code will not work.

    Also, where have you saved the image data? to a post, or something else?
    Your code of $curauth makes me think you are loading for a user

    Thanks
    E

  • I first had the format for the image field set at OBJECT, then URL, then ID. None of them worked. It’s currently set to OBJECT.

    You are correct. I’ve connected my field groups to the user profiles and then I display those fields on the author.php template page. All the fields show up correctly for the given user profile EXCEPT for the images (author.php is used to create a profile page).

    Here it is http://choochooclan.com/surrogate/author/Mar/

    If the rest of the fields work for user profiles, why does the image field have a problem?

  • Hi, i have same problem
    wp 3.8.1
    use image field in custom post type and output in index page, but fields empty

  • @Elliott, Would it be easier for you to solve if I gave you ftp and admin acecess?

  • Hi @jimario

    The issue here is that you are loading from a user as describe in your other thread here:
    http://support.advancedcustomfields.com/forums/topic/hiding-emptyunhiding-non-empty-fields-not-working/#post-12765

    Please read the linked docs to learn how to correctly load from a user.

    Thanks
    E

  • Hi Elliott,

    I was excited to try the code found on the page you referred to. After trying it out, it still did not work. This is the code I used with my field name substituted in…it’s been inserted under the word “Profile”:

    <?php
     
    $author_id = get_the_author_meta( 'ID' );
    $author_badge = get_field('donor_image1', 'user_'. $author_id ); // image field, return type = "Image Object"
     
    ?>
    <img src="<?php echo $author_badge['url']; ?>" alt="<?php echo $author_badge['alt']; ?>" width="200" height="100" />

    Keep in mind that this isn’t for an actual post page but is for an author page (author.php). The url is http://choochooclan.com/surrogate/author/egglady/ or http://choochooclan.com/surrogate/?author=11 Given that the author ID is 11, I would think that the code would pull that in dynamically and then look for the appropriate image field which is donor_image1 and then display it accordingly. As you can see this is not happening. Is there something else I need to add to the code?

  • This reply has been marked as private.
  • Hi @jimario

    Please debug your code line by line and confirm that on each line, the variables and parameters are all correct.

    Thanks
    E

  • Hi, I’ve debugged using

    
    ini_set('display_errors', 'On');
    error_reporting(E_ALL | E_STRICT);
    

    I also made sure to remove all other code and only run this code that I got from ACF’s knowledge base:

    `
    $author_id = get_the_author_meta( ‘ID’ );
    $author_badge = get_field(‘imagex’, ‘user_’. $author_id ); // image field, return type = “Image Object”
    `
    ?>
    ” alt=”<?php echo $author_badge[‘alt’]; ?>” width=”200″ height=”60″ />
    `

    Debugging the code turned up nothing. My sample page is here: http://choochooclan.com/surro-test/?author=5

  • May I ask:
    what does the source code in the browser looks like? Is it filling in any field or an incorrect path to the file?

    if it looks like this, the code is not looking at the right custom field:

  • Nohl. I don’t see what you’re referring to. I did look at the source code and the answer would be no, it isn’t filling in any field, not even an incorrect path to the file. This is all that gets returned:

    <img src="" alt="" width="200" height="60" />

  • I saw this problem once when I changed the name of a custom field in WP. The old slug stays the same in the DB.

    Did you change the name of the field after you added it?

  • No. I’ve also tested additional image field names that I created. They don’t work either. If you want, you can take a look at the page in question:

    http://www.choochooclan.com/surrogate/

    user: debx
    pass: 1

    When you log in you’ll be taken directly to the user edit profile page. The You’ll have to scroll down and then select the Photographs link from the nav menu on the left to find the Add Image buttons. Simply add some images if you want and update. Then scroll back to the top of the page and click on “View my profile”. That will take you to the front-end profile page where you can check out the page source. Some of the pictures should show up at the top but as you can see, they don’t.

  • This is the syntax i used for displaying an image:
    <img src="<?php the_field('site_plan'); ?>" alt="" />

    site_plan is the field slug.

    It’s not totally clear that it’s displaying the text fields. Can you confirm?

  • Text fields are displaying if there’s text data for that field. I used your script you just posted and that didn’t work. I’m still getting

    <img src="" alt="" />

    when I view page source. All the fields display as they should except Images. I don’t know why I’m having a problem with this.

  • in the screen that show the format for custom fields, do you have “the Return Value” set to “image url”? –> if you switch to “Image id” what do you get?

  • Yes, I had it set to “image url”. I first had it set to “Image Object” then “image url”. Neither worked. I just tested “Image ID” and that didn’t work either. 🙁

  • I finally resolved this. Elliott had given me the correct direction but being limited in my php ability I failed to see my obvious mistake. The correct code can be found in the Documents HERE at the bottom of the page.

    Basically it shows an example of displaying a custom field named “author_badge” which means all you have to do is replace author_badge with your actual custom field name. I only replaced it in the places where “author_badge” appeared in orange type. I finally replaced all instances of author_badge with my own image name and voila, the picture appeared.

    Hopefully this helps other script kiddies. Thank you, Elliot for an amazing plugin.

  • This reply has been marked as private.
  • It seems to be only half solved. Images display correctly on front-end profiles EXCEPT for profiles whose users have yet to create a post or page. If a user hasn’t created a post or page, the images they upload to their back-end profiles will not display on their front-end profiles.

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

The topic ‘Images Not Showing Up on Pages’ is closed to new replies.