Advertisement
Guest User

Untitled

a guest
Sep 30th, 2011
284
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.36 KB | None | 0 0
  1. <?php
  2. global $shortname;
  3.  
  4. define('PER_PAGE_DEFAULT', get_option($shortname.'_general_posts_per_page'));
  5.  
  6. /*-----------------------------------------------------------------------------------*/
  7. /* = Custom function for query posts
  8. /*-----------------------------------------------------------------------------------*/
  9.  
  10. if ( ! function_exists( 'max_query_posts' ) ):
  11.  
  12. function max_query_posts($showposts, $catArray, $random = false, $offset = false) {
  13. $off = !$offset ? "" : $offset;
  14. $rand = !$random ? "" : $random;
  15. $tag_id = !$tag_id ? "" : $tag_id;
  16.  
  17. global $wp_query;
  18. wp_reset_query();
  19.  
  20. $paged = get_query_var('paged') ? get_query_var('paged') : 1;
  21.  
  22. // Check if catArray is a array or single cat
  23. $cat_string = is_array($catArray) ? implode( ',' , $catArray ) : $catArray;
  24.  
  25. $defaults = array(
  26. 'paged' => $paged,
  27. 'posty_type' => 'gallery',
  28. 'posts_per_page' => PER_PAGE_DEFAULT,
  29. GALLERY_TAXONOMY => $cat_string,
  30. 'orderby' => $rand,
  31. 'offset' => $offset
  32. );
  33.  
  34. $query = $defaults;
  35. $wp_query = new WP_Query($query);
  36. }
  37. endif;
  38.  
  39.  
  40. /*-----------------------------------------------------------------------------------*/
  41. /* = Custom function for query term posts
  42. /*-----------------------------------------------------------------------------------*/
  43.  
  44. if ( ! function_exists( 'max_query_term_posts' ) ):
  45. function max_query_term_posts($showposts = PER_PAGE_DEFAULT, $id_array, $type = 'gallery', $random = false, $taxonomy = GALLERY_TAXONOMY, $order = false){
  46.  
  47. $rand = !$random ? "" : $random;
  48. $order = !$order ? "" : $order;
  49.  
  50. $posts_to_query = get_objects_in_term($id_array, $taxonomy);
  51.  
  52. return query_posts( array( 'showposts'=> $showposts, 'post_type' => $type, 'post__in' => $posts_to_query, 'orderby' => $rand, 'order'=> $order) );
  53. }
  54. endif;
  55.  
  56.  
  57. /*-----------------------------------------------------------------------------------*/
  58. /* = Custom function for query posts by tags
  59. /*-----------------------------------------------------------------------------------*/
  60.  
  61. if ( ! function_exists( 'max_query_tag_posts' ) ):
  62. function max_query_tag_posts($showposts = PER_PAGE_DEFAULT, $type = 'gallery', $tag_slug = false){
  63. $tag = !$tag_slug ? "" : $tag_slug;
  64. return query_posts( array( 'showposts'=> $showposts, 'post_type' => $type, 'tag'=> $tag) );
  65. }
  66. endif;
  67.  
  68.  
  69. /*-----------------------------------------------------------------------------------*/
  70. /* = Get a image url from post id
  71. /*-----------------------------------------------------------------------------------*/
  72.  
  73. function max_get_post_image_url($id, $size = 'full'){
  74. return wp_get_attachment_image_src( get_post_thumbnail_id( $id ), $size);
  75. }
  76.  
  77.  
  78. /*-----------------------------------------------------------------------------------*/
  79. /* = Get a Post Image depending on Options set in Options Panel
  80. /*-----------------------------------------------------------------------------------*/
  81.  
  82. function max_get_post_custom_image( $return = false, $p_id = false ){
  83.  
  84. global $shortname, $post, $imgDimensions;
  85.  
  86. $post_id = !$p_id ? $post->ID : $p_id;
  87.  
  88. // check if its a lightbox or a project page link
  89. $photo_item_type = get_post_meta($post_id, $shortname.'_photo_item_type_value', true);
  90.  
  91. // Get the post image via timthumb
  92. $imgUrl = max_get_post_image_url($post_id, "full");
  93.  
  94. $output = "";
  95.  
  96. if( !isset( $imgDimensions['width'] ) ) {
  97. $width = "";
  98. $imgWidth = "";
  99. }else{
  100. $width = "&amp;w=".$imgDimensions['width'];
  101. $imgWidth = ' width="' . $imgDimensions['width'] . ' "';
  102. }
  103. if( !isset( $imgDimensions['height'] ) ) {
  104. $height = "";
  105. $imgHeight = "";
  106. }else{
  107. $height = "&amp;h=".$imgDimensions['height'];
  108. $imgHeight = ' height="' . $imgDimensions['height'] . ' "';
  109. }
  110.  
  111. if ( has_post_thumbnail( $post_id ) ) {
  112.  
  113. // check if to show lightbox desc and title
  114. if ( get_option_max( 'pretty_title_show' ) == 'true' ){
  115. $title = ' title="' . get_the_excerpt() . '"';
  116. }
  117.  
  118. $cat_list = array();
  119.  
  120. foreach(get_the_category() as $category){
  121. $cat_list[] = $category->cat_ID;
  122. }
  123.  
  124. if ( !in_array( get_option_max('general_blog_id'), $cat_list ) ) {
  125.  
  126. // Photo Type is a Lightbox
  127. if($photo_item_type == "Lightbox" ){
  128.  
  129. // Display Lightbox Photo
  130. if ( get_post_meta($post_id, $shortname.'_photo_lightbox_type_value', true) == "Photo" ){
  131.  
  132. $output .= '<a href="' . $imgUrl[0] . '" rel="prettyPhoto[gal]"'.$title.'><img src="' . get_template_directory_uri() . '/timthumb.php?src=' . $imgUrl[0] . $width . $height . '&amp;a=' . get_cropping_direction( get_post_meta($post_id, $shortname.'_photo_cropping_direction_value', true) ) . '&amp;q=100" alt="' . get_the_title() .'"' . $imgWidth . $imgWidth . '" /></a>';
  133.  
  134. }
  135.  
  136. // Display Lightbox YouTube Video
  137. if ( get_post_meta($post_id, $shortname.'_photo_lightbox_type_value', true) == "YouTube-Video" ){
  138.  
  139. $output .= '<a href="' . get_post_meta($post_id, $shortname.'_photo_video_youtube_value', true) . '" rel="prettyPhoto" title="' . get_the_title() . '"><img src="' . get_template_directory_uri() . '/timthumb.php?src=' . $imgUrl[0] . $width . $height . '&amp;a=' . get_cropping_direction( get_post_meta($post_id, $shortname.'_photo_cropping_direction_value', true) ) . '&amp;q=100" alt="' . get_the_title() .'"' . $imgWidth . $imgWidth . '" /></a>';
  140.  
  141. }
  142.  
  143. // Display Lightbox Vimeo Video
  144. if ( get_post_meta($post_id, $shortname.'_photo_lightbox_type_value', true) == "Vimeo-Video" ){
  145.  
  146. $output .= '<a href="' . get_post_meta($post_id, $shortname.'_photo_video_vimeo_value', true) . '" rel="prettyPhoto" title="' . get_the_title() . '"><img src="' . get_template_directory_uri() . '/timthumb.php?src=' . $imgUrl[0] . $width . $height . '&amp;a=' . get_cropping_direction( get_post_meta($post_id, $shortname.'_photo_cropping_direction_value', true) ) . '&amp;q=100" alt="' . get_the_title() .'"' . $imgWidth . $imgWidth . '" /></a>';
  147.  
  148. }
  149.  
  150. }else if($photo_item_type == "Project Page" ){
  151.  
  152. // Photo Type is a Project Page
  153. $output .= '<a href="' . get_permalink($post_id) . '" title="' . get_the_title() . '"><img src="' . get_template_directory_uri() . '/timthumb.php?src=' . $imgUrl[0] . $width . $height . '.&amp;a=' . get_cropping_direction( get_post_meta($post_id, $shortname.'_photo_cropping_direction_value', true) ) . '&amp;q=100"' . $imgWidth . $imgWidth . '" alt="' . get_the_title() . '" class="fade-image"/></a>';
  154.  
  155. }else if($photo_item_type == "External Link" ){
  156.  
  157. // Photo Type is an external Link
  158. $output .= '<a href="' . get_post_meta($post_id, $shortname.'_photo_external_link_value', true) . '" title="' . get_the_title() . '"><img src="' . get_template_directory_uri() . '/timthumb.php?src=' . $imgUrl[0] . $width . $height . '.&amp;a=' . get_cropping_direction( get_post_meta($post_id, $shortname.'_photo_cropping_direction_value', true) ) . '&amp;q=100"' . $imgWidth . $imgWidth . '" alt="' . get_the_title() . '" class="fade-image"/></a>';
  159.  
  160. }else{
  161. // Get the timbthumb image
  162. $output .= '<a href="'. $imgUrl[0] .'" rel="prettyPhoto" title="'. get_the_excerpt() .'">
  163. <img src="' . get_template_directory_uri(). '/timthumb.php?src=' . $imgUrl[0] . $height . $width.'&amp;a='. get_cropping_direction( get_post_meta($post_id, $shortname.'_photo_cropping_direction_value', 2313) ) . '&amp;q=100"' . $imgWidth . $imgWidth . '" class="fade-image" alt="' . get_the_title() . '" title="' . get_the_title() . '" />
  164. </a>';
  165. }
  166.  
  167. }else{
  168.  
  169. // Get the timbthumb image
  170. $output .= '<a href="'. $imgUrl[0] .'" rel="prettyPhoto"'.$title.'>
  171. <img src="' . get_template_directory_uri(). '/timthumb.php?src=' . $imgUrl[0] . $height . $width.'&amp;a='. get_cropping_direction( get_post_meta($post_id, $shortname.'_photo_cropping_direction_value', 2313) ) . '&amp;q=100"' . $imgWidth . $imgWidth . '" class="fade-image" alt="' . get_the_title() . '" title="' . get_the_title() . '" />
  172. </a>';
  173. }
  174.  
  175.  
  176. }
  177.  
  178. if($return === true){
  179. return $output;
  180. }else{
  181. echo $output;
  182. }
  183. }
  184.  
  185.  
  186. /*-----------------------------------------------------------------------------------*/
  187. /* = Get a Post Lightbox CSS Class
  188. /*-----------------------------------------------------------------------------------*/
  189.  
  190. function max_get_post_lightbox_class(){
  191.  
  192. global $shortname, $post, $imgDimensions;
  193.  
  194. $lightbox_type = get_post_meta($post->ID, $shortname.'_photo_lightbox_type_value', true);
  195.  
  196. switch($lightbox_type){
  197.  
  198. case "Photo": $class = "photo";
  199. break;
  200.  
  201. case "YouTube-Video": $class = "youtube-video";
  202. break;
  203.  
  204. case "Vimeo-Video": $class = "vimeo-video";
  205. break;
  206.  
  207. default: $class = "photo";
  208. break;
  209.  
  210. }
  211.  
  212. return $class;
  213.  
  214. }
  215.  
  216. /*-----------------------------------------------------------------------------------*/
  217. /* = Custom excerpt function
  218. /*-----------------------------------------------------------------------------------*/
  219.  
  220. function max_get_the_excerpt( $echo = false ){
  221.  
  222. global $shortname, $post;
  223.  
  224. $excerpt = $post->post_excerpt;
  225.  
  226. if ($excerpt != "" ) {
  227. if ( $echo === true ) {
  228. the_excerpt();
  229. }else{
  230. return $excerpt;
  231. }
  232. }
  233.  
  234. return false;
  235.  
  236. }
  237.  
  238.  
  239. ?>
  240.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement