Archive for May, 2010

Creating Named Widgets in WordPress Made Simple

Creating your own widgets in WordPress might seem like a complicated or confusing task but the truth is, it’s easier than you think!

In your the root of your theme directory (ex: wp-content/themes/default), you’ll find a file called “functions.php”, if you do not, create it.

Inside add:

if ( function_exists('register_sidebar') ) {
   register_sidebar(array("id" => "facts_and_stats",
			"name" =>"Facts and Stats"
   ));
}

(all attributes can be found here: http://codex.wordpress.org/Function_Reference/register_sidebar)

In the backend, under “appearance > widgets”, you’ll find all available widgets and all available sidebars. You can drag a widget into the sidebar and customize it.

Then in a template file in your theme, say your “index.php” file, you can call the content of this widget with the following block of code:

< ?php if ( function_exists('dynamic_sidebar') && dynamic_sidebar("facts_and_stats") ) { } ?>

Widgets are wrapped in <li></li> by default, you can custom a group of them with a trick such as the following, where I remove all wrappers for multiple widgets by creating an array setting the before_ and afters_’s to nothing and merge it with the id and name info in another array I create inline.

$widget_args=array(
	'before_widget' => '',
	'after_widget' => '',
	'before_title' => '',
	'after_title' => '',
);

if ( function_exists('register_sidebar') ) {
   register_sidebar(array_merge($widget_args,array("id" => "facts_and_stats", "name" =>"Facts and Stats")));
   register_sidebar(array_merge($widget_args,array("id" => "report_card", "name" =>"Report Card")));
}

Another trick I I like to do is add a quick link on the frontend for to the edit page if the user is logged in an has rights to edit widgets:

<?php if (current_user_can('manage_options')) { echo '<a href="'.get_bloginfo('url').'/wp-admin/widgets.php" title="edit this widget">edit this widget</a>'; } ?>

Fastest way to install the media essentials in ubuntu

If you’re coming from Windows, or like me, find yourself living in a live CD while you figure out which step went wrong; you’ll be interested in the essential media codecs, flash, java, Microsoft fonts, etc.

I thought I’d share the way I did this as quickly as possible in in Ubuntu 10.04 using the command line.

Open up terminal, using ctrl+alt+t (Which I’m very happy about as this has been my default since 8.04). Alternativelty from the main menu -> Applications > Accessories > Terminal

Make a backup in case you’re scared, then remove the comments from repositories you need to unlock to access the restricted (proprietary) packages.

ubuntu@ubuntu:~$ sudo cp /etc/apt/sources.list .
ubuntu@ubuntu:~$ sudo sed -i 's/^# deb/deb/' /etc/apt/sources.list

We do this be matching the first 2 characters with ‘# ‘ and replacing them with ” (nothing). See the diff below (> indicate original lines, < are changed).


ubuntu@ubuntu:~$ diff sources.list /etc/apt/sources.list
18,23c18,23
< # deb http://archive.ubuntu.com/ubuntu lucid universe
< # deb-src http://archive.ubuntu.com/ubuntu lucid universe
< # deb http://archive.ubuntu.com/ubuntu lucid-updates universe
< # deb-src http://archive.ubuntu.com/ubuntu lucid-updates universe
< # deb http://security.ubuntu.com/ubuntu lucid-security universe
< # deb-src http://security.ubuntu.com/ubuntu lucid-security universe
---
> deb http://archive.ubuntu.com/ubuntu lucid universe
> deb-src http://archive.ubuntu.com/ubuntu lucid universe
> deb http://archive.ubuntu.com/ubuntu lucid-updates universe
> deb-src http://archive.ubuntu.com/ubuntu lucid-updates universe
> deb http://security.ubuntu.com/ubuntu lucid-security universe
> deb-src http://security.ubuntu.com/ubuntu lucid-security universe
30,35c30,35
< # deb http://archive.ubuntu.com/ubuntu lucid multiverse
< # deb-src http://archive.ubuntu.com/ubuntu lucid multiverse
< # deb http://archive.ubuntu.com/ubuntu lucid-updates multiverse
< # deb-src http://archive.ubuntu.com/ubuntu lucid-updates multiverse
< # deb http://security.ubuntu.com/ubuntu lucid-security multiverse
< # deb-src http://security.ubuntu.com/ubuntu lucid-security multiverse
---
> deb http://archive.ubuntu.com/ubuntu lucid multiverse
> deb-src http://archive.ubuntu.com/ubuntu lucid multiverse
> deb http://archive.ubuntu.com/ubuntu lucid-updates multiverse
> deb-src http://archive.ubuntu.com/ubuntu lucid-updates multiverse
> deb http://security.ubuntu.com/ubuntu lucid-security multiverse
> deb-src http://security.ubuntu.com/ubuntu lucid-security multiverse
>
<pre class="brush:bash">

Now that we uncommented these lines, they will be read next time we update, so lets go ahead and do that now. Once that is done, we can install the extras.

ubuntu@ubuntu:~$ sudo apt-get update
ubuntu@ubuntu:~$ sudo apt-get install ubuntu-restricted-extras

Rock and roll.

Packages for nautilus you wish were installed by default in ubuntu

Intro

Thanks to a tip I picked up at Tombuntu about nautilus, after following up on a trick to add files to mocp through nautilus scripts trackback link from Hilltop Yodler (great article), when doing a google search for GiS for nautilus-actions (apt-get install nautilus-actions). I learned about 3 kick ass additions to the nautilus menu. I realized Fedora Linux and Linux Mint had some of these in their context menus but didn’t make the connection to ubuntu until now.

On with the Show

sudo apt-get install nautilus-open-terminal nautilus-image-converter nautilus-gksu

for some kick ass options in the context (right click) menu of nautilus (your default file manager in ubuntu). For more information, check out the tombuntu article I linked above.

pkill nautilus

to restart nautilus and have the new packages in your context menu

More

If you’re interested in this, you’ll probably also like my article about nautilus-actions.