Advertisement
Guest User

Drupal 7 Image Style Conditional

a guest
Apr 12th, 2012
190
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.10 KB | None | 0 0
  1. I have two content types:
  2.  
  3. post_image_on_right and post_image_wide
  4.  
  5. post_image_on_right has three different image styles. What I would like to do is depending on what image style is being displayed give me that path or url of that image to push into a pinterest media attribute. I have a switch written but I think it's looking for a change in node type and not image style.
  6.  
  7. switch ($node->type) {
  8. case 'post_image_on_right':
  9. $image_field = 'field_image_right';
  10. $image_style = 'medium';
  11. break;
  12.  
  13. case 'post_image_on_right':
  14. $image_field = 'field_image_vertical';
  15. $image_style = 'medium_vertical';
  16. break;
  17.  
  18. case 'post_image_on_right':
  19. $image_field = 'field_image_tall';
  20. $image_style = 'medium_tall';
  21. break;
  22.  
  23. case 'post_wide_image':
  24. $image_field = 'field_image_wide';
  25. $image_style = 'large';
  26. break;
  27. }
  28.  
  29. $field_items = field_get_items('node', $node, $image_field);
  30.  
  31. <a class="addthis_button_pinterest" pi:pinit:url="<?php echo "http://" . $_SERVER['HTTP_HOST'] . $node_url ?>" pi:pinit:media="<?php print image_style_url($image_style, $field_items[0]['uri']); ?>" pi:pinit:layout="horizontal"></a>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement