Support

Account

Home Forums General Issues Displaying field from single.php in the homepage

Unread

Displaying field from single.php in the homepage

  • Hello there.
    I have a field (image) which related to a user image which I display in my single.php using this code:

    <?php
    		  $author_id = get_the_author_meta( 'ID' );
    		  $user_photo = get_field('user_photo', 'user_'. $author_id );
    
    		 if($user_photo){?>
           <img src="<?php echo $user_photo['url']; ?>" alt="<?php echo $user_photo['alt']; ?>" />
            <?php } else { ?>
            <img src="<?php bloginfo('template_directory'); ?>/images/shirt-default.png" alt="">
            <?php } ?>

    That displays correctly an image which a a user uploads from the admin inside the “users” section. it works just fine..

    Now – I am trying to show all the users with their images in my homepage
    I have a code which correctly displays the user names + links to their archive page:

    <?php
    foreach($users as $user)
    		{
    			?>
    	
    	  <div class="col-md-1 col-sm-2 col-xs-3 author"><a href="<?php echo get_author_posts_url( $user->ID ); ?>">
    		<div class="img-wrap"> <span class="author-name">
    		<?php echo $user->display_name; ?></span>
    <?php
    		  $author_id = get_the_author_meta( 'ID' );
    		  $user_photo = get_field('user_photo', 'user_'. $author_id );
    
    		 if($user_photo){?>
           <img src="<?php echo $user_photo['url']; ?>" alt="<?php echo $user_photo['alt']; ?>" />
            <?php } else { ?>
            <img src="<?php bloginfo('template_directory'); ?>/images/shirt-default.png" alt="">
            <?php } ?>
    		</div></a>
    	  </div>
    						  
    <?php
    		}
    	?>

    Also works except for showing the image ACF which is associated with each users.
    can anyone help?

    Thanks

Viewing 1 post (of 1 total)

The topic ‘Displaying field from single.php in the homepage’ is closed to new replies.