Changeset 189
- Timestamp:
- 01/10/05 23:02:46 (3 years ago)
- Files:
-
- mini-posts/trunk/mini-posts.php (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
mini-posts/trunk/mini-posts.php
r182 r189 4 4 Plugin URI: http://doocy.net/mini-posts/ 5 5 Description: An approach to "asides", or small posts. Allows you to mark entries as "mini" posts and handle them differently than normal posts. <strong>Requires WordPress 1.5.</strong> 6 Version: 0. 46 Version: 0.5 7 7 Author: Morgan Doocy 8 8 Author URI: http://doocy.net/ … … 37 37 0.3 - Updated to accommodate WP pages. 38 38 0.4 - Updated to accommodate feeds; added option to filter mini posts from feeds. 39 0.5 - Added support for 0-, 1-, and n-comment formatting to get_mini_posts(). 40 (WARNING: The argument sequence of get_mini_posts() has changed to accommodate this.) 39 41 40 42 */ … … 165 167 } 166 168 167 function get_mini_posts($format = '%post% %commentcount% %permalink%', $permalink_text = '', $ comment_count_format= '', $limit = '') {169 function get_mini_posts($format = '%post% %commentcount% %permalink%', $permalink_text = '', $zero_comments = '', $one_comment = '', $more_comments = '', $limit = '') { 168 170 global $wpdb; 169 171 … … 173 175 } 174 176 175 // Idiotproofing 177 // Determine whether a comment format was specified 178 if ('' == $zero_comments && '' == $one_comment && '' == $more_comments) 179 $comment_count_format = false; 180 else 181 $comment_count_format = true; 182 183 // If only the 'zero' format is specified, use the same for all three 184 if ('' != $zero_comments && '' == $one_comment && '' == $more_comments) 185 $one_comment = $more_comments = $zero_comments; 186 187 // Make $permalink_text and comment count formats coincide with $format, 188 // resolving any conflicts. 176 189 if ('' != $format) { 177 // Make $permalink_text and $comment_count_format178 // coincide with $format, resolving any conflicts.179 if (strstr($format, '%commentcount%') && '' == $comment_count_format)180 $comment_count_format = '(%s)';181 elseif (!strstr($format, '%commentcount%') && '' !=$comment_count_format)190 if (strstr($format, '%commentcount%') && !$comment_count_format) { 191 $zero_comments = $one_comment = $more_comments = '(%s)'; 192 $comment_count_format = true; 193 } 194 elseif (!strstr($format, '%commentcount%') && $comment_count_format) 182 195 $format = "$format %commentcount%"; 183 196 if (strstr($format, '%permalink%') && '' == $permalink_text) … … 188 201 $format = "%post% $format"; 189 202 } else { 190 // Make $format coincide with $permalink_text and $comment_count_format 191 if ('' != $permalink_text && '' != $comment_count_format) 203 if ('' != $permalink_text && $comment_count_format) 192 204 $format = '%post% %commentcount% %permalink%'; 193 elseif ('' == $permalink_text && '' !=$comment_count_format)205 elseif ('' == $permalink_text && $comment_count_format) 194 206 $format = '%post% %commentcount%'; 195 elseif ('' != $permalink_text && '' ==$comment_count_format)207 elseif ('' != $permalink_text && !$comment_count_format) 196 208 $format = '%post% %permalink%'; 197 elseif ('' == $permalink_text && '' ==$comment_count_format)209 elseif ('' == $permalink_text && !$comment_count_format) 198 210 $format = '%post%'; 199 211 } 200 212 201 if ( '' !=$comment_count_format && $commentcounts = $wpdb->get_results("SELECT ID, COUNT($wpdb->comments.comment_post_ID) AS comment_count FROM $wpdb->comments INNER JOIN $wpdb->posts ON ($wpdb->comments.comment_post_ID = $wpdb->posts.ID) INNER JOIN $wpdb->postmeta ON ($wpdb->posts.ID = $wpdb->postmeta.post_id) WHERE $wpdb->posts.post_status = 'publish' AND $wpdb->postmeta.meta_key = '_mini_post' AND $wpdb->postmeta.meta_value = '1' $exclusions GROUP BY $wpdb->posts.ID")) {213 if ($comment_count_format && $commentcounts = $wpdb->get_results("SELECT ID, COUNT($wpdb->comments.comment_post_ID) AS comment_count FROM $wpdb->comments INNER JOIN $wpdb->posts ON ($wpdb->comments.comment_post_ID = $wpdb->posts.ID) INNER JOIN $wpdb->postmeta ON ($wpdb->posts.ID = $wpdb->postmeta.post_id) WHERE $wpdb->posts.post_status = 'publish' AND $wpdb->postmeta.meta_key = '_mini_post' AND $wpdb->postmeta.meta_value = '1' $exclusions GROUP BY $wpdb->posts.ID")) { 202 214 foreach ($commentcounts as $commentcount) { 203 215 if ($commentcount > 0) { … … 227 239 } 228 240 229 if ( '' !=$comment_count_format) {241 if ($comment_count_format) { 230 242 $count = isset($minipost_commentcounts["$minipost->ID"]) ? $minipost_commentcounts["$minipost->ID"] : 0; 243 if ($count == 0) 244 $commentcounttext = $zero_comments; 245 elseif ($count == 1) 246 $commentcounttext = $one_comment; 247 else 248 $commentcounttext = $more_comments; 231 249 $commenturl = "$url#comments"; 232 $commentcount = sprintf("<a class=\"minipost_commentlink\" href=\"$commenturl\" title=\"Comments for '$title_text'\">$comment _count_format</a>", $count);250 $commentcount = sprintf("<a class=\"minipost_commentlink\" href=\"$commenturl\" title=\"Comments for '$title_text'\">$commentcounttext</a>", $count); 233 251 } 234 252
