| [ Index ] |
PHP Cross Reference of PageLines Framework |
[Summary view] [Print] [Text view]
1 <?php 2 /** 3 * Includes functions for use in layouts 4 * 5 **/ 6 7 8 9 /** 10 * 11 * @TODO document 12 * 13 */ 14 function grid( $data, $args = array() ){ 15 16 $defaults = array( 17 'data' => 'query', 18 'per_row' => 3, 19 'format' => 'img_grid', 20 'paged' => false, 21 'has_img' => true, 22 'image_field' => false, 23 'img_default' => null, 24 'img_width' => '100%', 25 'title' => '', 26 'title_link' => '', 27 'class' => 'pagelines-grid', 28 'row_class' => 'gridrow', 29 'content_len' => 10, 30 'callback' => false, 31 'margin' => true, 32 'hovercard' => false 33 ); 34 35 $a = wp_parse_args($args, $defaults); 36 37 if( $a['data'] == 'users' || $a['data'] == 'array_callback'){ 38 39 $posts = $data; 40 41 }else{ 42 // The Query 43 global $wp_query; 44 45 $wp_query = $data; 46 47 $posts = $data->posts; 48 49 if( !is_array( $posts ) ) 50 return; 51 52 } 53 54 // Standard Variables 55 $out = ''; 56 $total = count($posts); 57 $count = 1; 58 $default_img = ( isset($a['img_default']) ) ? sprintf('<img src="%s" alt="%s"/>', $a['img_default'], __('No Image', 'pagelines')) : ''; 59 60 $margin_class = ($a['margin']) ? '' : 'ppfull'; 61 62 63 if($a['hovercard']) 64 $out .= pl_js_wrap(sprintf('jQuery(".vignette").hover(function(){jQuery(this).find(".hovercard").fadeIn();}, function(){jQuery(this).find(".hovercard").fadeOut();});')); 65 66 67 // Grid loop 68 foreach($posts as $pid => $p){ 69 70 // Grid Stuff 71 $start = (grid_row_start( $count, $total, $a['per_row'])) ? sprintf('<div class="pprow grid-row fix %s">', $margin_class) : ''; 72 $end = (grid_row_end( $count, $total, $a['per_row'])) ? '</div>' : ''; 73 $last_class = (grid_row_end( $count, $total, $a['per_row'])) ? 'pplast' : ''; 74 75 76 // Content 77 $content = ''; 78 79 if($a['callback']) 80 $content = call_user_func( $a['callback'], $p, $a ); 81 else { 82 83 setup_postdata($p); 84 85 $oset = array('post_id' => $p->ID); 86 87 // The Image 88 if( $a['image_field'] && ploption($a['image_field'], $oset) ) 89 $thumb = sprintf('<img src="%s" alt="thumb" />', ploption($a['image_field'], $oset) ); 90 elseif( has_post_thumbnail( $p->ID ) ) 91 $thumb = get_the_post_thumbnail( $p->ID ); 92 else 93 $thumb = $default_img; 94 95 $hovercard = ($a['hovercard']) ? sprintf('<div class="hovercard"><span>%s</span></div>', $p->post_title) : ''; 96 97 $image = sprintf( 98 '<a href="%s" class="img grid-img" style="width: %s"><div class="grid-img-pad"><div class="grid-img-frame"><div class="vignette">%s%s</div></div></div></a>', 99 get_permalink($p->ID), 100 $a['img_width'], 101 $thumb, 102 $hovercard 103 ); 104 105 $content .= $image; 106 107 // Text 108 109 if($a['format'] == 'media'){ 110 111 $content .= sprintf( 112 '<div class="bd grid-content"><h4><a href="%s">%s</a></h4> <p>%s %s %s</p></div>', 113 get_permalink($p->ID), 114 $p->post_title, 115 custom_trim_excerpt($p->post_content, $a['content_len']), 116 sprintf('<a href="%s" >More →</a>', get_permalink($p->ID)), 117 pledit( $p->ID ) 118 119 ); 120 121 } 122 123 } 124 125 // Column Box Wrapper 126 $out .= sprintf( 127 '%s<div class="grid-element pp%s %s %s"><div class="grid-element-pad">%s</div></div>%s', 128 $start, 129 $a['per_row'], 130 $a['format'], 131 $last_class, 132 $content, 133 $end 134 ); 135 136 $count++; 137 } 138 139 if( $a['paged'] ){ 140 ob_start(); 141 pagelines_pagination(); 142 $pages = ob_get_clean(); 143 } else 144 $pages = ''; 145 146 $title_link = ($a['title_link'] != '') ? sprintf('<a href="%s" class="button title-link">See All</a>', $a['title_link']) : ''; 147 148 $title = ($a['title'] != '') ? sprintf('<div class="grid-title"><div class="grid-title-pad fix"><h4 class="gtitle">%s</h4>%s</div></div>', $a['title'], $title_link) : ''; 149 150 $wrap = sprintf('<div class="plgrid %s"><div class="plgrid-pad">%s%s%s</div></div>', $a['class'], $title, $out, $pages); 151 152 return $wrap; 153 154 } 155 156 157 /** 158 * Returns true on the first element in a row of elements 159 **/ 160 function grid_row_start( $count, $total_count, $perline){ 161 162 $row_count = $count + ( $perline - 1 ); 163 164 $grid_row_start = ( $row_count % $perline == 0 ) ? true : false; 165 166 return $grid_row_start; 167 168 } 169 170 /** 171 * Returns false on the last element in a row of elements 172 **/ 173 function grid_row_end( $count, $total_count, $perline){ 174 175 176 $row_count = $count + ( $perline - 1 ); 177 178 $box_row_end = ( ( $row_count + 1 ) % $perline == 0 || $count == $total_count ) ? true : false; 179 180 return $box_row_end; 181 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated: Sat Apr 6 23:00:27 2013 | Cross-referenced by PHPXref 0.7.1 |