-->

Our WordPress Mods

We did a few things to WordPress to support the icons we’re using. In the course of upgrading from 1.5.2 to 2.0.1, I had to do them over again. That reminded me it might be good to share them. jandrugs.com

caveat: I did these in WP 1.5.2 after finding no way to get what I wanted in options or template programming. I haven’t checked out WP 2.0.1 to see if there is a ‘right’ way to get the same affect.

#1, we wanted to present the icons along with links, where available. You can see these in the ‘Links’ and ‘News’ section of the sidebar. WP allows support for an image, but then replaces the link name with it. We wanted both the icon and the name.

I modified the file wp-includes/links.php near line 250 from:
    if (($row->link_image != null) && $show_images) {
       if (strstr($row->link_image, ‘http’))
          $output.= “link_image’ $alt $title >”;
       else // If it’s a relative path
          $output.= “link_image’ $alt $title />”;
    } else {
       $output.= $name;
    }

by inserting one line to modify the behavior when the image is a .ico file:
    if (($row->link_image != null) && $show_images) {
       if (strstr($row->link_image, ‘http’))
          $output.= “link_image’ $alt $title >”;
       else // If it’s a relative path
          $output.= “link_image’ $alt $title >”;
       if (substr($row->link_image, -4) == ‘.ico’) $output .= ‘ ‘ . $name; // append name to .ico files (link icons)
    } else {
       $output.= $name;
    }

#2, we wanted to use category icons in the posts in addition to the category names. Since it was in addition, we wanted the normal behavior left alone. So we set up the template to call the the_category() function a second time, passing ‘icon’ as the separator argument (yeah, it’s a bit kludgy). Then down in wp-includes/template-functions-category.php at about line 70:
      }
      $thelist .= ‘’;
   } else {
      $i = 0;
      foreach ($categories as $category) {

I added a new test based on the separator:
      }
      $thelist .= ‘’;
   } elseif ($separator == ‘icon’) {
      foreach ($categories as $category) {
         $thelist = “category_nicename}.png\” align=\”right\”>\n” . $thelist;
      }
   } else {
      $i = 0;
      foreach ($categories as $category) {

And yes, we use .png instead of .gif even though MSIE doesn’t properly render the transparent .png files yet.

#3 the last item was to get the list of categories in the sidebar to act as a guide to the categories as well. This is the real kludge, since we are actually disabling a ‘normal’ WP behavior and replacing it with our preferred behavior. Also in wp-includes/template-functions-category.php at about line 373:
      if ( $list ) {
        $thelist .= “\t

  •         if (($category->cat_ID == $wp_query->get_queried_object_id()) && is_category()) {
                $thelist .= ‘ class=”current-cat”‘;
            }
            $thelist .= “>$link\n”;
          } else {
            $thelist .= “\t$link
    \n”;
          }

  • I comment out the category display and insert my own:
          if ( $list ) {
    // kludge - table my catagory icons here
    //         $thelist .= “\t
  • //         if (($category->cat_ID == $wp_query->get_queried_object_id()) && is_category()) {
    //            $thelist .= ‘ class=”current-cat”‘;
    //         }
    //         $thelist .= “>$link\n”;
            $thelist .= “\t category_nicename}.png\” align=\”left\”>
    $link”;
    // end kludge
          } else {
            $thelist .= “\t$link
    \n”;
          }

    Enjoy!

    Trackback

    Leave a Comment

    Your first comment is human moderated to reduce spam. It can take us a while (hours) to do that. Subsequent comments will appear much faster. We greatly sympathize with any frustration this causes, but given the amount of spam we have to deal with already we're not likely to change things soon.

    You must be logged in to post a comment.