Listing Top Categories in Wordpress

For my footer, I wanted to list the top ten categories (as calculated by the number of posts in each category). Bizarrely enough, there isn't an easy built-in way to do this with Wordpress. What's more surprising is that I couldn't find a plugin that provided this functionality, either. Maybe I'm the only person with this requirement. At any rate, this is how I solved the issue:

  1. <?php
  2.  
  3. $top_cats = $wpdb->get_results("SELECT * FROM $wpdb->categories ORDER BY category_count DESC LIMIT 10");
  4.  
  5. foreach($top_cats as $cat)
  6. {
  7. $cat_link = '<a href="index.php"' . $cat->category_nicename . '">';
  8. $cat_li = "<li>$cat_link $cat->cat_name</a></li> ";
  9. echo($cat_li);
  10. }
  11.  
  12. ?>

Arrow Icon Set

Arrow Icon Set Preview

Download the icons

One of these days, I'm going to figure out how to transform a Windows icon file into a Mac and a Linux icon file, but until that time...

Enjoy! :-D

Genghis Kahn Template

Genghis Khan Template Screenshot

Err — yeah.

You might be wondering what Genghis Kahn has to do with the template. The short answer: he doesn't. The long answer: I needed to name the template something — it was either "Red Blue White" or "Genghis Kahn," and I settled for the latter. I shall contrive to come up with a slightly more meaningful title next time. ;-)

View the template Download the template

Free Template: Earthy

Earthy Template Screenshot

Long-time users might notice that the design looks suspiciously familiar to one of the previous revisions of this blog. That's because — err — it had been used as the design for this blog at one point. However, I'm not using it any longer (no kidding). I didn't want to let it go for waste, however, and so I'm releasing it as a free template for anyone who wants to use it for personal or commercial site. Feel free to make any modifications whatever. However, please don't try to sell the design to anyone. :-)

While you don't need to include my name in the design anywhere, a mention and a link back is much appreciated. :-D

Look at the template

Download the files

Registering Server Controls in Web.Config

A useful addition to ASP .NET 2.0 is the ability to register web controls in web.config. In ASP .NET 1.1, if you wanted to use a custom server control on twenty different pages, you had to register it on all twenty of those pages:

  1. <%@ Register tagprefix="tagprefix" Namespace="Namespace" Assembly="Assembly" %>

In ASP .NET 2.0, you can register the server control in the controls section of web.config once and use it in whatever page you want of the web application.

  1. <pages>
  2. <controls>
  3. <add
  4. tagPrefix="MyTagPrefix"
  5. namespace="My.Namespace"
  6. assembly="MyAssembly"/>
  7. </controls>
  8.  
  9. <!-- Other elements go here -->
  10.  
  11. </pages>

Read more on MSDN

Two Cents On Access Modifiers in C#

Access Modifiers

Access modifiers, as their name suggests, control who sees what in an application. C# has 4 basic access modifiers (there’s also a 5th one, but more on that later). Here they are, listed from least restrictive to most restrictve.

  1. public: accessible anywhere.
  2. protected: accessible to current class and all derived classes.
  3. internal: accessible to any class in the current assembly.
  4. private: accessible to current class only.

Easy enough to understand.

Some Things to Keep In With Access Modifiers

  1. Namespaces can’t have access modifiers. They’re always public. So: public namespace AwesomeNewNamespace { … } will produce a compile-time error.
  2. Classes can be either public or internal but not protected or private. So: private class AwesomeNewClass { … } will produce a compile-time error. This makes sense if you think about it — how exactly would you use a private or a protected class??
  3. Interfaces, like classes, can be either public or internal but not protected or private.
  4. Methods defined in interfaces can’t have access modifiers.
  5. Enums are always public. They can’t have access modifiers either.
  6. By default, classes are internal. So: class NotSoCool { … } is equivalent to internal class NotSoCool { … }.
  7. By default, methods in class are private. So void SomeAwesomeMethod() { … } is equivalent to private void SomeAwesomeMethod() { … }.
  8. Same goes for variables (fields): private unless specified otherwise.
  9. Needless to say, you can’t use access modifiers on variables inside a method: public voidMethod() { protected string someString; will produce a compile-time error.
  10. Derived classes can either have the same restriction level or can be more restrictive than the base class but not less restrictive. So: internal class Base { … } public class Child : Base { } will produce a compile-time error.

Now that we got that out of the way, let’s take a look at that 5th modifier that I mentioned at the beginning. This would be the compound modifier protected internal. After looking at it for a minute, you would think that it does what other compound modifiers in .NET do. For example, protected virtual void AwesomeMethod() makes AwesomeMethod both virtual and protected, so you’d think that protected internal AwesomeClass { … } would make the class both protected and internal (i.e., it is only accessible to derived classes in the assembly) but you would be wrong. For some bizarre reason that I have yet to fathom, the powers-to-be have decided that protected internal means protected or internal (so that the method is available to all derived classes as well as all classes in the current assembly).

Windows Media Player 11 Beta

I’m a converted iTunes junkie. The last time I’ve opened Windows Media Player was, like, in the Dark Ages. Nothing wrong with the player, but its user interface is horrendous, especially when compared to the simple elegance of iTunes.

But I just might get converted back to Windows Media Player. Microsoft finally released the Windows Media Player 11 Beta, and I have to say, I’m impressed. :-)

Windows Media Player 11 Beta 2 Screenshot From Microsoft

Source: Microsoft

Here’s a link to the Windows Media Player 11 Beta download for those of you who want to play with it.

Granting EXECUTE Permissions on All Stored Procedures

Something I’ve had to do often. Until now, I’ve gone through the “laborous” (hehe) process of remembering what stored procedures I’ve added and granting EXECUTE permissions to whatever user for each procedure. I was sure that there was an easier way to grant the permission on all stored procedures, and there is!

GRANT EXECUTE TO [Insert the name of the user here]

If you’re using SQL Server 2000, you don’t have it so easy. However, here’s an article on how to create a stored procedure to do the same.

14 of 17 pages « First  <  12 13 14 15 16 >  Last »

On the Side