Subscribe to RSS Subscribe to Comments

Commafruit

This one slipped under my radar somehow: Microsoft have changed the default rendering behaviour of Internet Explorer 8. Previously, the plan was that IE8 would behave as IE7, unless the developer added a special <meta> tag. Now, the default is to use the (slightly more standards compliant) IE8 renderer by default, but give the developer the option to use IE7-style rendering (again, but means of a <meta> tag). PPK sums it up nicely:

Microsoft has decided to put the interests of web standards above the interests of the Intranets of its corporate clients.

I advise you to read the previous paragraph again. Even two years ago I had never expected to be able to write such a statement.

[...]
Tags: , , ,
AddThis Social Bookmark Button

FancyZoom is a Lightbox-like JavaScript library for browsing images on a webpage. Actually, I think it’s better than Lightbox in some ways, great animation.

[...]
Tags: , , ,
AddThis Social Bookmark Button

Site upgrade, Wordpress 2.3.1, Tags

So, I’ve finally upgraded this site to use a version 2.x series Wordpress. This version (2.3.1) includes tagging support built in, which was a big plus for me as I’d be looking at installing something like UTW, but putting it off because I knew I planned to upgrade. Installation/upgrade of Wordpress is impressively straightforward by the way.

Anyway, after going through and tagging most of my entries, it was clear that I had a small number of tags with like 20 posts, and then lots of others with 1-5, which meant I had a list of words with a couple of them highlighted, but unable to see the difference between a tag with 1 post and one with 4. Luckily, I know PHP. :)

The code below replaces the wp_generate_tag_cloud function in the wp-includes/category-template.php file. Essentially, rather than taking the default distribution of number of posts for a tag then calculating the size, it takes the natural log (aka ln or loge), which results in a more even distribution, and so more similarly sized tags!

This code was marked up using the wonderful GeSHi.

  1. function wp_generate_tag_cloud( $tags, $args = ) {
  2.         global $wp_rewrite;
  3.         $defaults = array(
  4.                 ’smallest’ => 8, ‘largest’ => 22, ‘unit’ => ‘pt’, ‘number’ => 45,
  5.                 ‘format’ => ‘flat’, ‘orderby’ => ‘name’, ‘order’ => ‘ASC’
  6.         );
  7.         $args = wp_parse_args( $args, $defaults );
  8.         extract($args);
  9.         if ( !$tags )
  10.                 return;
  11.         $counts = $tag_links = $counts_display = array();
  12.         foreach ( (array) $tags as $tag ) {
  13.                 $counts[$tag->name] = log($tag->count) + 1;
  14.                 $counts_display[$tag->name] = $tag->count;
  15.                 $tag_links[$tag->name] = get_tag_link( $tag->term_id );
  16.                 if ( is_wp_error( $tag_links[$tag->name] ) )
  17.                         return $tag_links[$tag->name];
  18.                 $tag_ids[$tag->name] = $tag->term_id;
  19.         }
  20.         $min_count = min($counts);
  21.         $spread = max($counts)$min_count;
  22.         if ( $spread <= 0 )
  23.                 $spread = 1;
  24.         $font_spread = $largest$smallest;
  25.         if ( $font_spread <= 0 )
  26.                 $font_spread = 1;
  27.         $font_step = $font_spread / $spread;
  28.         // SQL cannot save you; this is a second (potentially different) sort on a subset of data.
  29.         if ( ‘name’ == $orderby )
  30.                 uksort($counts, ’strnatcasecmp’);
  31.         else
  32.                 asort($counts);
  33.         if ( ‘DESC’ == $order )
  34.                 $counts = array_reverse( $counts, true );
  35.         $a = array();
  36.         $rel = ( is_object($wp_rewrite) && $wp_rewrite->using_permalinks() ) ? ‘ rel="tag"’ : ;
  37.         foreach ( $counts as $tag => $count ) {
  38.                 $tag_id = $tag_ids[$tag];
  39.                 $tag_link = clean_url($tag_links[$tag]);
  40.                 $tag = str_replace(‘ ‘, ‘&nbsp;’, wp_specialchars( $tag ));
  41.                 $a[] = "<a href=’$tag_link’ class=’tag-link-$tag_id’ title=’" . attribute_escape( sprintf( __(‘%d topics’), $counts_display[str_replace(‘&nbsp;’,‘ ‘,$tag)] ) ) . "’$rel style=’font-size: " .
  42.                         ( $smallest + ( ( $count$min_count ) * $font_step ) )
  43.                         . "$unit;’>$tag</a>";
  44.         }
  45.         switch ( $format ) :
  46.         case ‘array’ :
  47.                 $return =& $a;
  48.                 break;
  49.         case ‘list’ :
  50.                 $return = "<ul class=’wp-tag-cloud’>\n\t<li>";
  51.                 $return .= join("</li>\n\t<li>", $a);
  52.                 $return .= "</li>\n</ul>\n";
  53.                 break;
  54.         default :
  55.                 $return = join("\n", $a);
  56.                 break;
  57.         endswitch;
  58.         return apply_filters( ‘wp_generate_tag_cloud’, $return, $tags, $args );
  59. }
Tags: , , , ,
AddThis Social Bookmark Button

Fixfox Web Developer Extension

Was shown this plug-in for Firefox. It’s an add-in which adds a “web developer toolbar” to Firefox, presenting you with a bewildering array of options, including the ability to disable various elements (such as images, java, javascript, etc.), but also provides more advanced functionality like in-place CSS editing, and this is just scratching the surface. An incredibly useful tool.

Tags: ,
AddThis Social Bookmark Button