Posts tagged as "how-to":

How-To: Override the Search Widget in Your Wordpress Theme

May 23, 2008

As I’ve mentioned previously I’ve been developing my own Wordpress theme. During the course of this I found, as many others have, the ‘Search’ widget available in the Wordpress sidebar does not use the searchform.php file which template developers can provide. This irritated me and I was pretty sure the behavior of the ‘Search’ widget could be overridden in functions.php. I was right… I found the beginning of the answer in the Wordpress Widget API but to me the language of

It is possible for theme authors to define replacement widgets within functions.php. Replace an existing widget by registering its name with a new callback. An empty callback will unregister a widget.

was a little convoluted. As it turns out you need to do two things.

First, define a new function to use as the ‘widget callback’ or the function that is called when the widget is included in the page.

    function bjs_widget_search($args) {
        extract($args);
        echo $before_widget;
        echo $before_title;
        _e("Search");
        echo $after_title;
        include (TEMPLATEPATH . '/searchform.php');
        echo $after_widget;
    }

Second, re-register the search widget using your new function name as the callback function.

    $widgetOptions = array('classname' => 'widget_search', 'description' => ( "A search form for your blog"));
    wp_register_sidebar_widget('search',('Search'),'bjs_widget_search',$widgetOptions);

And that’s all there is to it. You may notice that I actually did more than just make the search widget include searchform.php I also added a header tag with a title for the widget. Keep in mind if you use ids for your search form elements this may invalidate your markup if the search form appears (or can) more than once on your page

How-To: Adding Foldings to Javascript Files in MacVim

May 20, 2008

Having used TextMate for a while I have grown quite accustomed to being able to fold sections of code, particularly function declarations, so I can glance through the file to see what functions and variables I have defined. However, I recently made a totally nerd bragging rights based decision to test out MacVim. Well it wasn’t all bragging rights, being able to navigate a file without having to move my fingers from ‘home base’ would be a big plus.

The project I’m currently working on though has a couple of really large javascript files and navigating them quickly in MacVim without the foldings was something I found to be quite difficult so I started looking at the Vim help files and found the ability to create folds. Due to a disciplined use of tabs to indent code blocks :set foldmethod=indent worked fairly well but eventually it started to bug me because the of the fold was actually the first line of the content which meant the folds looked something like functionName: function() {
+ - - if (test) {
},
There had to be a better way. I realized what I wanted to do was create a fold on the line with the function declaration down to the line with the ending brace. I could not find an easy command to do this so I created a simple javascript filetype plugin (addfoldings vim plugin).

In order to get this to work I had to add filetype plugin on to my .vimrc file and I had to create the ~/.vim/ftplugin/javascript directory and drop the addfoldings.vim file into it. By default the foldings are all open but they have been created.

Update: Things are of course never as easy as they seem. The above works fine as long as you don’t add lines to the file you’re working on which is of course absurd, additionally it won’t update the foldings as you go which sort of limits the usefulness. Hopefully I’ll be able to update this to be more useful.

How-To: Run Firefox2 and Firefox3 Simultaneously on a Mac

May 9, 2008

I’ve found a number of step by steps to set this up on a Windows machine, the most in-depth being on Lifehacker. However, I haven’t found a quick one to set up multiple profiles on the Mac.

My reason for wanting to do this was pretty simple; I wanted to be able to play with Firefox3 while still using Firefox2 and the magic of Firebug for debugging and web development. As I knew from the many PC articles I just needed to set up a profile for each browser. Since I already had Firefox2 in my Applications folder (Firefox.app) I opened up terminal and ran /Applications/Firefox.app/Contents/MacOS/firefox -ProfileManager which brings up a screen allowing you to manage existing profiles and create new ones it should look something like this… Firefox Profile ManagerAs you can see I’ve already added the profile, yours will probably only have one profile called default and will have the “Don’t ask at startup” checked. The first thing I did was rename the default profile to Firefox2 (since that is what I already had installed and had been using). Then I created a new profile called Firefox3 and unchecked “Don’t ask at startup”. Easy as pie. After that I renamed Firefox.app in my Applications folder to Firefox2.app, downloaded the Firefox3 beta, copied it to Applications and renamed it to Firefox3.app.

The drawback is that whenever I launch either application it asks me which profile to use and I have to select the profile I want. I probably could edit the actual shell script at /Applications/Firefox2.app/Contents/MacOS/firefox and /Applications/Firefox3.app/Contents/MacOS/firefox respectively and hardcode the -P option in order to avoid this minor hassle but at this point it doesn’t seem worth it.

Update: after realizing I knew how I would do it if I wanted to setup default profiles it really started to bother me that I had to select a profile every time so I tried the method outlined above and it doesn’t work. Well it does if you start Firefox by running the script at /Applications/Firefox3.app/Contents/MacOS/firefox but that’s not what I foresee most people doing.