Some weeks ago I received a customer request to add a character counter to a textarea field and I made it using “classic” Javascript. Now that I’m learning jQuery and have some spare time, I tryed to transform my custom function to a jQuery plugin.
This is my first attempt to build a jQuery plugin and maybe there’s already another plugin that does the same thing but it have been a really nice exercise.
This plugin will give you the method setCounter([maxLength]). If you call it on a textarea field you will get a counter that gets updated every time the user write a character.
The maxLength parameter is not mandatory so if it’s undefined you will get a simple character counter like this:
while if you pass an integer to the method the user won’t be able to write a number of character greater than maxLength and you will get a counter like this:
I’ve just installed Lotus Notes 8.5 on Ubuntu and the first thing I noticed was the horrible fonts used in the interface. I’ve searched for a setting, but couldn’t find none so Goggle helped me: Notes is looking for a font called Luxi contained in the package ttf-xfree86-nonfree.
I know that mixing scriplets and JSTL in JSP is a bad practice, but sometimes you can’t avoid it and every time I do it I can’t remember how to share variables between scriplets and JSTL so this post is a sort of reminder for the future. Hope it can be useful for other forgetful persons like me :-)
Added the option to choose if Javascript files should be included in the header or in the footer of the page. This option is available only if you are using WordPress 2.8 and above
I’ve just released Selective Javascript Loader my first WordPress plugin. It’s a very simple plugin that automatically loads different Javascript files based on the blog section that is being viewed (index, category, single post, page).
It can be really useful if you make extensive use of Javascript in your theme and want to split the code and load functions only when you need them.
A simple JavaScript function to check date validity
123456789101112131415161718
functioncheckDateValidity(day,month,year){month=month-1;varmessage='';vardate=newDate(year,month,day);if(year!=date.getFullYear())message='Year not valid';if(month!=date.getMonth())message='Month not valid';if(day!=date.getDate())message='Day not valid';returnmessage;}
Using the new Firefox awesome bar could result in a frustrating experience, because the SQLite database that holds all the data used by Firefox can get heavily defragmented.
You can get an huge speed improvement running this command inside the Firefox error console:
This function must be called inside the single.php template: it gets the first post’s category, searches for a template named like singlepost_first_category_slug.php and returns its path; if the file doesn’t exists it will return the single_default.php_ template path.
Her tip is really simple and really useful: just rename your single.php to single1.php and create a new single2.php with your category specific layout; after that, create a new single.php file with this code:
WordPress has a simple function to build a search form for your blog and in this tutorial I’ll show you how to add a category filter to it.
1
<?phpget_search_form();?>
This function will look for a file called searchform.php inside your template folder: if it doesn’t exist it will output the standard search form. So, if it isn’t already in place, create your custom searchform.php and copy into it the default search form output. It should look similar to this:
We want to add a select box to let the user search in a specific category or in all categories: to achive this we’ll use another default WordPress
function.
The wp_dropdown_categories function will build for you a select box with all your categories. Take a look at the documentation for all the available options.
<!-- This is a sample output of the function --><selectname='cat'id='cat'class='postform'><optionvalue='0'selected='selected'>All Categories</option><optionclass="level-0"value="1">Uncategorized</option><optionclass="level-0"value="3">HTML & CSS</option><optionclass="level-0"value="4">Java</option><optionclass="level-0"value="5">Links</option><optionclass="level-0"value="6">Linux</option><optionclass="level-0"value="9">Javascript</option><optionclass="level-0"value="32">XML</option></select>
Now add the category select box to the form modifying your searchform.php
like this:
Now that you have a nice category filter in your search form it would be great to modify the search result page and add something like Search result for “foo” in category “bar”. Well, it’s quite easy: we need do add a simple function to the function.php file. Remember that every function in this file will be automatically available in your theme.
This is a simple function that gets the cat parameter from the request and if it’s not null it searches the category name. It has two input parameters so you can pass two strings to be displayed before and after the category name. If cat is null or empty or “0” (All categories) it will return an empty string.