Support

Account

Home Forums Front-end Issues Images are showing up on frontend

Solving

Images are showing up on frontend

  • I am trying to show Images using custom fields. But it’s not working. Can you check.

    Below is the code

    <?php
    // Show the Gallery
    if( have_rows(‘gallery_slideshow’) ):

    echo ‘<div class=”projects-gallery-wrap”>’;
    echo ‘<div class=”projects-gallery”>’;

    // loop through the rows of data
    while ( have_rows(‘gallery_slideshow’) ) : the_row();

    $imgObj = get_sub_field(‘image’, $post->ID);

    echo ‘'.$imgObj[alt].'‘;

    endwhile;

    echo ‘</div>’;
    echo ‘</div>’;

    endif;
    ?>

    http://divinepower.co.in/cof/projects/contract/waikiki-honolulu/

    The same code is working okay on different custom post type.

  • Hi Sargamgupta,

    It’s quite hard to read your code, if you highlight it and select the ‘code’ button on the menu above the text box it will display it in a nicer format and make it easier for people to help you 🙂

    It looks like you are returning the alt tag for the image rather than the url, try this instead;

    <?php echo $imgObj['url']; ?>

    You may want to separate your markup from your PHP which will make it again easier to understand, and also wrap and img tag around your output –

    <?php // Show the Gallery
    if( have_rows(‘gallery_slideshow’) ): ?>
    <div class="projects-gallery-wrap">
      <div class="projects-gallery">
    
      <?php // loop through the rows of data
      while ( have_rows(‘gallery_slideshow’) ) : the_row(); ?>
    
        <?php $imgObj = get_sub_field(‘image’, $post->ID); ?>
        <img src="<?php echo $imgObj[url]; ?>" alt="<?php echo $imgObj[alt]; ?>">
    
      <?php endwhile; ?>
    
      </div>
    </div>
    <?php endif; ?>

    You may also want to check you are outputting the image object and not the URL/ID in the backend.

    Let me know how it goes.

  • Hi @sargamgupta

    Just chiming in on another thing. The get_sub_field() function does not need (nor take) a second parameter of the post id so please remove that. You’ll only need the field name as a single parameter in any get_sub_field() or the_sub_field().

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

The topic ‘Images are showing up on frontend’ is closed to new replies.