Support

Account

Forum Replies Created

  • Ok for some reason that messed up the javascript on my page. How do I just get the actual image size/uncropped?

    <?php $image = get_field('ceo_background'); echo($image['sizes']['medium']); ?>

    See attached screenshot for what my custom fields look like.

    If I use ‘medium’ in the code – it crops it. I tried ‘full’ and it returned no image. I just want the uncropped version.

  • Nope. Still doesn’t work. And yes I have registered the custom image size in the functions file.

    Here is the my full code for the template page. As you can see I am querying two different images “current” and “previous”. I’ve left the query for “previous” as is and it is working (just not with the custom image size. The code you provided is now returning the links with the alt text.

    <div id="scroller">
    
    <?php $args = array(
    	'numberposts' => -1,
    	'post_type' => 'as-investments',
    	'meta_key' => 'investment_status',
    	'meta_value' => 'Current'
    );
    $the_query = new WP_Query( $args ); ?>
    
    <?php if( $the_query->have_posts() ): ?>
    
    <?php while ( $the_query->have_posts() ) : $the_query->the_post(); ?>
    
    <div class="banner-logo">
      <?php
        $attachment_id = get_field('investment_logo');
        $size = "banner-logo"; // (thumbnail, medium, large, full or custom size)
        $image = wp_get_attachment_image_src( $attachment_id, $size );
        // url = $image[0];
        // width = $image[1];
        // height = $image[2];
      ?>
      <a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>" rel="bookmark">
        <img class="investment_logo" alt="Image of <?php the_title(); ?>" src="<?php echo $image[0]; ?>" />
      </a>
    </div>
    
    <?php endwhile; ?>
    
    <?php endif; ?>
    <?php wp_reset_query();  // Restore global post data stomped by the_post(). ?>
    
    <?php $args = array(
    	'numberposts' => -1,
    	'post_type' => 'as-investments',
    	'meta_key' => 'investment_status',
    	'meta_value' => 'Previous'
    );
    $the_query = new WP_Query( $args ); ?>
    
    <?php if( $the_query->have_posts() ): ?>
    
    <?php while ( $the_query->have_posts() ) : $the_query->the_post(); ?>
    
    	<div id="banner-logo">
    <a href="<?php the_permalink() ?>" title="<?php printf(__('%s','rys'), get_the_title()) ?>" rel="bookmark" >
    <img class="investment_logo" alt="" src="<?php $image = get_field('investment_logo'); echo($image['sizes']['medium']); ?>" />
    </a>
    	</div>
    
    <?php endwhile; ?>
    
    <?php endif; ?>
    <?php wp_reset_query();  // Restore global post data stomped by the_post(). ?>
                                    
    </div>
    

    functions.php file:

    if ( function_exists( 'add_image_size' ) ) add_theme_support( 'post-thumbnails' );
    
    	if ( function_exists( 'add_image_size' ) ) {
    	add_image_size( 'grid-thumb', 79, 79, true );
    	add_image_size( 'profile-thumb', 125, 152, true );
    	add_image_size( 'investment-logo', 151, 98, true );
    	add_image_size( 'banner-logo', 108, 70, true );
    }
    

    See attached screenshot for custom fields.

    Just to note: I am calling this image in two different locations on the site. One is where the image size needs to be 151×98 (investment logo) and then again for 108×70 (banner logo). I’m not sure if it matters but in the custom fields I have the “Investment Logo” selected.

  • That is not working… Here is what I have now and now I’m not getting any results back.

    
    <div>
    <?php
    $attachment_id = get_field('field_name');
    $size = "custom-size"; // (thumbnail, medium, large, full or custom size)
    $image = wp_get_attachment_image_src( $attachment_id, $size );
    // url = $image[0];
    // width = $image[1];
    // height = $image[2];
    ?>
    
    <a href="<?php the_permalink() ?>" title="<?php printf(__('%s','rys'), get_the_title()) ?>" rel="bookmark" >
    <img class="image-class" alt="" src="<?php echo $image[0]; ?>" />
    </a>
    
    </div>
    
    
  • Doesn’t work. Still returning the label.

    Here is what my code looks like:

    $the_query = new WP_Query( $args ); ?>
    
    <ul>
    	<?php if( $the_query->have_posts() ): ?>
    	<?php while ( $the_query->have_posts() ) : $the_query->the_post(); ?>
    	
    		<?php 
    		$value = get_field('industry_subsector'); 
    		?>
    		<li id="<?php echo $value; ?>">
    			<?php the_field('industry_subsector'); ?>
    		</li>
    
    	<?php endwhile; ?>
    <?php endif; ?>
    </ul>
    

    Here is what I get…

    <ul>	
    	<li id="Building Products">Building Products</li>
    	<li id="General Industrial">General Industrial</li>
    	<li id="Specialty Chemicals">Specialty Chemicals</li>
    	<li id="Measurement & Controls">Measurement & Controls</li>
    	<li id="Automotive">Automotive</li>
    </ul>
    

    My field choices look like this:

    
    automotive : Automotive
    building_products : Building Products
    measurement_controls : Measurement & Controls
    paper_packaging : Paper/Packaging
    general_industrial : General Industrial
    specialty_chemicals : Specialty Chemicals
    

    I want it to look like this:

    <ul>	
    	<li id="building_products">Building Products</li>
    	<li id="general_industrial">General Industrial</li>
    	<li id="specialty_chemicals">Specialty Chemicals</li>
    	<li id="measurement_controls">Measurement & Controls</li>
    	<li id="automotive">Automotive</li>
    </ul>
    

    What am I doing wrong?

  • I am having the same problem as well.

    I’m using the following code in my theme functions file

    function datepicker_to_unix( $date ){
    	$dateparts = explode('/', $date);
    	$unixtimestamp = strtotime(date('d.m.Y', strtotime($dateparts[1].'/'.$dateparts[2].'/'.$dateparts[0])));
    	return $unixtimestamp;
    }

    And then the following in my template file

    <?php $date = get_field('field_name'); echo date('F d, Y', datepicker_to_unix($date )); ?>
    

    The result outputs: January 01, 1970

  • Thank you SO much! This is what I ended up with…

    <div>
    		
    		<?php $associations = get_field('associations');
    		if( $associations ): ?>
    		
    		<?php foreach( $associations as $association): ?>
    			<?php 
    			$photo = get_field('investment_logo', $association->ID); ?>
    					
    			<a href="<?php the_permalink() ?>" title="<?php printf(__('%s','rys'), get_the_title()) ?>" rel="bookmark">
    			<img src="<?php echo $photo['url']; ?>" alt="<?php echo $photo['alt']; ?>" />
    			</a>
    			
    		<?php endforeach; ?>
    
    		<?php endif; ?>
    
    		<a href="<?php the_permalink() ?>" title="<?php printf(__('%s','rys'), get_the_title()) ?>" rel="bookmark" >
    		<?php the_title(); ?></a>
    
    		<em><?php the_field('publication_source'); ?></em>
    
    		<span><?php $date = get_field('publication_date'); echo date('F d, Y', datepicker_to_unix($date )); ?></span>
    
    		</div>

    Really appreciate your quick response! Thank you!!

  • Yes, I am aware that I need to put the relationship code within my loop but I don’t know what the code should be. Every time I tried adding it, I got a php error. I’m confused because I’m already querying multiple different posts on the page (unlike the documentation which shows an example of querying for a single template file).

    Please see the screenshots for what I’m working with. I know this is slightly complicated but I’m sure folks would want to know how to do this as well.

    I want to query the image somewhere between this div.

    <div>
    		
    <a href="<?php the_permalink() ?>" title="<?php printf(__('%s','rys'), get_the_title()) ?>" rel="bookmark" ><?php the_title(); ?></a>
    
    		<em><?php the_field('publication_source'); ?></em>
    
    <span><?php $date = get_field('publication_date');
    			echo date('F d, Y', datepicker_to_unix($date )); ?></span>
    		</div>

    Really appreciate your help! Thank you!!

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