Advertisement
Guest User

Passing Variables to a Function

a guest
Feb 15th, 2012
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.66 KB | None | 0 0
  1. <?php function getGallery($galleryLink, $altLink){
  2.  
  3.     global $post;
  4.    
  5.     // 1. search for any pages with a custom field of 'test' that have a value of 'yes'
  6.     query_posts('meta_key='.$galleryLink.'&post_type=page');
  7.  
  8.  
  9.     if ( have_posts() ) while ( have_posts() ) : the_post();
  10.         // 2. echo the test field
  11.         $link =  get_post_meta($post->ID, $galleryLink, true);
  12.         $alt =  get_post_meta($post->ID, $altLink, true); ?>
  13.     <img src="<?php echo $link ?>" alt="<?php echo $alt ?>" />
  14.     <?php endwhile;
  15.  
  16.     wp_reset_query();
  17.  
  18. }?>
  19.  
  20. <?php getGallery('Gallery - Promotion Gallery Photo Link', 'Gallery - Promotion Gallery Photo Alt text'); ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement