web/wp-content/themes/IRI-Theme/functions.php
branchwordpress
changeset 109 03b0d1493584
child 123 561aa6d282f6
equal deleted inserted replaced
-1:000000000000 109:03b0d1493584
       
     1 <?php
       
     2 
       
     3 function getPost($post = NULL) {
       
     4 	include('post.php');
       
     5 }
       
     6 
       
     7 function getSearch($q = NULL) {
       
     8 	include('searchform.php');
       
     9 }
       
    10 
       
    11 if ( function_exists('register_sidebar') )
       
    12 {
       
    13     register_sidebar
       
    14     (   array
       
    15         (
       
    16           'name' => 'Sidebar-Single',
       
    17           'before_widget' => '<div class="bottombar">',
       
    18           'after_widget' => '</div>',
       
    19           'before_title' => '<h2 class="widgettitle">',
       
    20           'after_title' => '</h2>',
       
    21         )
       
    22     );
       
    23 	register_sidebar
       
    24     (   array
       
    25         (
       
    26           'name' => 'Sidebar-Single-home',
       
    27           'before_widget' => '<div class="bottombar">',
       
    28           'after_widget' => '</div>',
       
    29           'before_title' => '<h2 class="widgettitle">',
       
    30           'after_title' => '</h2>',
       
    31         )
       
    32     );
       
    33     register_sidebar
       
    34     (   array
       
    35         (
       
    36           'name' => 'Bottom-Left',
       
    37           'before_widget' => '<div class="bottombar">',
       
    38           'after_widget' => '</div>',
       
    39           'before_title' => '<h2 class="widgettitle">',
       
    40           'after_title' => '</h2>',
       
    41         )
       
    42     );  
       
    43     register_sidebar
       
    44     (   array
       
    45         (
       
    46           'name' => 'Bottom-Middle',
       
    47           'before_widget' => '<div class="bottombar">',
       
    48           'after_widget' => '</div>',
       
    49           'before_title' => '<h2 class="widgettitle">',
       
    50           'after_title' => '</h2>',
       
    51         )
       
    52     );   
       
    53  register_sidebar
       
    54     (   array
       
    55         (
       
    56           'name' => 'Bottom-Right',
       
    57           'before_widget' => '<div class="bottombar">',
       
    58           'after_widget' => '</div>',
       
    59           'before_title' => '<h2 class="widgettitle">',
       
    60           'after_title' => '</h2>',
       
    61         )
       
    62     );   
       
    63 }
       
    64 
       
    65 
       
    66 
       
    67 # Displays a list of categories
       
    68 function cy_list_categories($Eparam='') {
       
    69 
       
    70 	$categories = get_categories('hide_empty=1'.$Eparam);
       
    71 	$first = true; $count = 0;
       
    72 	foreach ($categories as $category) {
       
    73 		$count++; if ($count>6) break; // limit to 5
       
    74 		if ($category->parent<1) {
       
    75 			if ($first) { $first = false; $f = ' class="f"'; } else { $f = ''; }
       
    76 			
       
    77 			echo ('<li '.$f.'>');
       
    78 			echo ('<a href="'.get_category_link($category->cat_ID).'">'.$category->name.' '.$raquo.'</a>');
       
    79 			
       
    80 			
       
    81 				echo '<ul>';
       
    82 				 $category_posts=get_posts('category='.$category->cat_ID);
       
    83 				 $count2=0;
       
    84 					foreach($category_posts as $post) {
       
    85 						$count2++; if ($count2>6) break;
       
    86 						echo '<li><a href="'.$post->guid.'">'.$post->post_title.'</a></li>';
       
    87 					};
       
    88                 echo "</ul></li>";
       
    89 
       
    90 			
       
    91 		}
       
    92 	}
       
    93 }
       
    94 
       
    95 # Displays a list of categories
       
    96 function dp_list_categories($Eparam='') {
       
    97 
       
    98 	$categories = get_categories('hide_empty=1'.$Eparam);
       
    99 	$first = true; $count = 0;
       
   100 	foreach ($categories as $category) {
       
   101 		$count++; if ($count>6) break; // limit to 5
       
   102 		if ($category->parent<1) {
       
   103 			// if ($first) { $first = false; $f = ' class="f"'; } else { $f = ''; }
       
   104 			
       
   105 			echo ('<li class="menu-h-li">');
       
   106 			echo ('<a href="'.get_category_link($category->cat_ID).'">'.$category->name.' '.$raquo.'</a>');
       
   107 			
       
   108 			
       
   109 				echo '<ul>';
       
   110 				 $category_posts=get_posts('category='.$category->cat_ID);
       
   111 				 $count2=0;
       
   112 					foreach($category_posts as $post) {
       
   113 						$count2++; if ($count2>6) break;
       
   114 						echo '<li class="menu-h-li2"><a href="'.$post->guid.'">'.$post->post_title.'</a></li>';
       
   115 					};
       
   116                 echo "</ul></li>";
       
   117 
       
   118 			
       
   119 		}
       
   120 	}
       
   121 }
       
   122 
       
   123 function dp_list_posts($Eparam='') {
       
   124 
       
   125 		$category_posts = get_posts($Eparam);
       
   126 		
       
   127 		foreach($category_posts as $post) {
       
   128 			echo '<li><a href="'.$post->guid.'">'.$post->post_title.'</a></li>';
       
   129 		};
       
   130 }
       
   131 
       
   132 
       
   133 /*
       
   134 Plugin Name: Get The Image
       
   135 Plugin URI: http://justintadlock.com/archives/2008/05/27/get-the-image-wordpress-plugin
       
   136 Description: This is a highly intuitive script that gets an image either by custom field input or post attachment.
       
   137 Version: 0.1 Beta
       
   138 Author: Justin Tadlock
       
   139 Author URI: http://justintadlock.com
       
   140 License: GPL
       
   141 */
       
   142 
       
   143 /***********************************************************
       
   144 Catchall function for getting images
       
   145 ***********************************************************/
       
   146 function get_the_image($arr = false, $default_size = 'medium', $default_img = false) {
       
   147 	global $post;
       
   148 	$cf_array = load_the_image($arr, $post, $default_size);
       
   149 	$image = display_the_image($cf_array, $post, $default_size, $default_img);
       
   150 	if($image == false) $image = '<!-- No images were added to this post. -->';
       
   151 	return $image;
       
   152 }
       
   153 
       
   154 /***********************************************************
       
   155 Catchall function for getting images with a link
       
   156 ***********************************************************/
       
   157 function get_the_image_link($arr = false, $default_size = 'medium', $default_img = false) {
       
   158 	global $post;
       
   159 	$cf_array = load_the_image($arr, $post, $default_size);
       
   160 	$image = display_the_image($cf_array, $post, $default_size, $default_img);
       
   161 
       
   162 	if($image == false) :
       
   163 		$image_link = '<!-- No images were added to this post. -->';
       
   164 	else :
       
   165 		$post_perm = get_permalink($post->ID);
       
   166 		$image_link = "<a href=\"$post_perm\" title=\"$post->post_title\">$image</a>";
       
   167 	endif;
       
   168 	return $image_link;
       
   169 }
       
   170 
       
   171 /***********************************************************
       
   172 Function for loading an image
       
   173 ***********************************************************/
       
   174 function load_the_image($custom_fields = false, $en_post, $default_size) {
       
   175 
       
   176 // Checks only if there are custom fields to check for
       
   177 	if(isset($custom_fields)) {
       
   178 
       
   179 	// Loop through the custom fields, checking for images or video
       
   180 		$i = 0;
       
   181 		while(strcmp($image[0],'') == 0 && $i <= sizeof($custom_fields)) {
       
   182 
       
   183 		// Check custom field values for image, image alt text, and image class
       
   184 			$image = get_post_custom_values($key = $custom_fields[$i]);
       
   185 			$image_alt = get_post_custom_values($key = $custom_fields[$i] . ' Alt');
       
   186 			$image_class = get_post_custom_values($key = $custom_fields[$i] . ' Class');
       
   187 		// Convert custom field key name to image class
       
   188 			$img_class = $custom_fields[$i];
       
   189 			$img_class = strtolower($img_class);
       
   190 			$img_class = str_replace (" ", "-", $img_class);
       
   191 
       
   192 		// Add space to image class if user inputs an extra class
       
   193 			if($image_class == true) $image_class .= ' ';
       
   194 
       
   195 		// Add user image class to default image classes
       
   196 			if($default_size == 'thumbnail' && $img_class == 'thumbnail') $image_class .= $default_size;
       
   197 			elseif($default_size == 'medium' && $img_class == 'medium') $image_class .= $default_size;
       
   198 			elseif($default_size == 'full' && $img_class == 'full') $image_class .= $default_size;
       
   199 			else $image_class .= $img_class . ' ' . $default_size;
       
   200 
       
   201 		$i++;
       
   202 		} // End while loop
       
   203 	} // End check for custom field image
       
   204 
       
   205 // If there is no image set through custom fields, check post attachments
       
   206 	if($image == false && $default_size == true) {
       
   207 		$img_att_arr = find_attachment_image($custom_fields[0], $en_post, $default_size);
       
   208 		if(strcmp($image_att_arr[0],'') == 0) :
       
   209 			$image = $img_att_arr[0];
       
   210 			$image_class = $img_att_arr[1];
       
   211 			$image_alt = false;
       
   212 		else :
       
   213 			$image = false; $image_alt = false; $image_class = false;
       
   214 		endif;
       
   215 	}
       
   216 
       
   217 // Return array with an image, image alt, and image class
       
   218 	return array($image, $image_alt, $image_class);
       
   219 }
       
   220 
       
   221 /***********************************************************
       
   222 Function for displaying an image
       
   223 ***********************************************************/
       
   224 function display_the_image($cf_array = false, $en_post = false, $default_size = false, $default_img = false) {
       
   225 
       
   226 // Set nice names for image info
       
   227 	if($cf_array[0] == false && $default_img == true) :
       
   228 		$image[0] = $default_img;
       
   229 		$image_class = $default_size;
       
   230 	else :
       
   231 		$image = $cf_array[0];
       
   232 		$image_alt = $cf_array[1];
       
   233 		$image_class = $cf_array[2];
       
   234 	endif;
       
   235 
       
   236 // If there's any kind of image for this post
       
   237 	if(isset($image[0]) && strcmp($image[0],'') != 0) :
       
   238 	// Open img tag
       
   239 		$output = '<img src="'.$image[0].'"';
       
   240 		$output .= ' alt="';
       
   241 	// Image alt text
       
   242 		if(isset($image_alt[0]) && strcmp($image_alt[0],'') != 0) $output .= $image_alt[0];
       
   243 		else $output .= $en_post->post_title;
       
   244 	// Image class
       
   245 		$output .= '" class="';
       
   246 		if(isset($image_class[0])) $output .= $image_class;
       
   247 		else $output .= 'left';
       
   248 	// Close img tag
       
   249 		$output .= '" />';
       
   250 // If there's no image
       
   251 	else :
       
   252 		$output = false;
       
   253 	endif;
       
   254 // Return the image
       
   255 	return $output;
       
   256 }
       
   257 
       
   258 /***********************************************************
       
   259 Function for finding an attachment image.
       
   260 Only called if no custom field images are set.
       
   261 ***********************************************************/
       
   262 function find_attachment_image($custom_fields = false, $en_post = false, $default_size = 'medium') {
       
   263 
       
   264 	$custom = $custom_fields;
       
   265 	$custom = strtolower($custom);
       
   266 	$custom = str_replace (" ", "-", $custom);
       
   267 // Don't repeat the same class name
       
   268 	if($custom == 'thumbnail' || $custom == 'medium' || $custom == 'full') $img_class = $default_size;
       
   269 	else $img_class = $custom . ' ' . $default_size;
       
   270 
       
   271 	$attachments = get_children("post_parent=$en_post->ID&post_type=attachment&post_mime_type=image&orderby=\"menu_order ASC, ID ASC\"&numberposts=1");
       
   272 	if($attachments == true) :
       
   273 		foreach($attachments as $id => $attachment) :
       
   274 			$img = wp_get_attachment_image_src($id, $default_size);
       
   275 			$img_arr[0] = $img;
       
   276 		endforeach;
       
   277 		$img_arr[1] = $img_class;
       
   278 	else :
       
   279 		$img_arr = false;
       
   280 	endif;
       
   281 	return $img_arr;
       
   282 }
       
   283 ?>