Changeset 189

Show
Ignore:
Timestamp:
01/10/05 23:02:46 (3 years ago)
Author:
morganiq
Message:

Added support for 0-, 1-, and n-comment formatting to get_mini_posts().

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • mini-posts/trunk/mini-posts.php

    r182 r189  
    44Plugin URI: http://doocy.net/mini-posts/ 
    55Description: 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.4 
     6Version: 0.5 
    77Author: Morgan Doocy 
    88Author URI: http://doocy.net/ 
     
    37370.3    - Updated to accommodate WP pages. 
    38380.4    - Updated to accommodate feeds; added option to filter mini posts from feeds. 
     390.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.) 
    3941 
    4042*/ 
     
    165167      } 
    166168       
    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 = '') { 
    168170            global $wpdb; 
    169171             
     
    173175            } 
    174176             
    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. 
    176189            if ('' != $format) { 
    177                   // Make $permalink_text and $comment_count_format 
    178                   // 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) 
    182195                        $format = "$format %commentcount%"; 
    183196                  if (strstr($format, '%permalink%') && '' == $permalink_text) 
     
    188201                        $format = "%post% $format"; 
    189202            } 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) 
    192204                        $format = '%post% %commentcount% %permalink%'; 
    193                   elseif ('' == $permalink_text && '' != $comment_count_format) 
     205                  elseif ('' == $permalink_text && $comment_count_format) 
    194206                        $format = '%post% %commentcount%'; 
    195                   elseif ('' != $permalink_text && '' == $comment_count_format) 
     207                  elseif ('' != $permalink_text && !$comment_count_format) 
    196208                        $format = '%post% %permalink%'; 
    197                   elseif ('' == $permalink_text && '' == $comment_count_format) 
     209                  elseif ('' == $permalink_text && !$comment_count_format) 
    198210                        $format = '%post%'; 
    199211            } 
    200212             
    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")) { 
    202214                  foreach ($commentcounts as $commentcount) { 
    203215                        if ($commentcount > 0) { 
     
    227239                              } 
    228240                               
    229                               if ('' != $comment_count_format) { 
     241                              if ($comment_count_format) { 
    230242                                    $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; 
    231249                                    $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); 
    233251                              } 
    234252