Forums

[resolved] I want to retrieve a custom field image instead of a thumbnail (3 posts)

  1. Phildub
    Member
    Posted 1 year ago #

    The wp theme I am using has a featured section on the front page. It pulls an article from a specified category and pulls the related photo too.

    The problem is that it's set to pull the 'thumbnail' image which is set up in the custom field. I don't want it to. All my thumbnail images are 200px wide and so when they appear in the featured section they are reproduced too bog and are all pixelated.

    What I would like to do is set up another custom field called 'featured' and ask the featured section to pull its image from there instead. How do I do that?

    Here is the relevant code from my theme:

    <a href="#">
    			<?php unset($photo);
    				$photo = catch_that_image (get_the_id(), '', '');
    
    			   if ( current_theme_supports( 'post-thumbnails' ) && has_post_thumbnail() ) {
    				 the_post_thumbnail(array(60,9999, true));
    			   }
    
    			   else{ 
    
    				 if ($wpzoom_cf_use == 'Yes')
    				 {
    				  $photo= get_post_meta($post->ID, $wpzoom_cf_photo, true);
    				 } // if CF used
    				 else
    				 {
    				  if (!$photo)
    				  {
    					$photo = catch_that_image($post->ID);
    				  }
    				 } // if CF not used
    
    				 if ($photo)
    				 {
    				?>
    				 <img src="<?php bloginfo('template_directory'); ?>/scripts/timthumb.php?w=60&h=50&zc=1&src=<?php echo $photo; ?>" alt="<?php the_title(); ?>" />
    				<?php
    				 }
    				 else
    				 {
    				  echo"<img src=\""; bloginfo('template_directory'); echo"/images/blank2.jpg\" />";
    				 } // if $photo still does not exist
    
    			  } // if theme does not have a thumbnail
    		  ?> 			</a>

    `
    I think it should be quite simple, but I tried a few things and only managed to mess up my theme. I don't know php so it's easy fro me to go wrong - any ideas?

  2. esmi
    Theme Diva & Forum Moderator
    Posted 1 year ago #

    Try replacing:

    $photo= get_post_meta($post->ID, $wpzoom_cf_photo, true);

    with:

    $photo= get_post_meta($post->ID, 'featured', true);

  3. Phildub
    Member
    Posted 1 year ago #

    Thank you Esmi, that worked perfectly!

Topic Closed

This topic has been closed to new replies.

About this Topic