Tips and Tricks About Computers, Web Development, Linux, the Internet and the Like
Archive for May, 2010
Patching NextGEN Voting Plugin to Allow Showing of the Vote Form on Single Images
May 30th
Intro
NextGEN Voting is a plugin for the wordpress plugin NextGEN Gallery plugin. Keeping this in mind made the task of extending easier. NextGEN Gallery hooks into wordpress functions, NextGEN Voting hooks into NextGEN Gallery.
By default, NextGEN Voting hooks into the gallery view, giving access to a function that uses the image id for lookup. The only reason we see nothing if we try to paste the same template code into a page other than the recommended “nextgen-gallery/view/gallery.php” is because that function is not given access in any other view.
How-to Add Access to Use the Function in the Image Browser Template
Open “wp-content/plugins/nextgen-gallery-voting/ngg-voting.php”,
Look for:
add_filter("ngg_show_gallery_content", "nggv_show_gallery", 10, 2);Add After:
add_filter("ngg_show_imagebrowser_content", "nggv_show_imagebrowser", 10, 2);Look for:
function nggv_show_gallery($out, $gid) {
return $out.nggc_voteForm($gid, $buffer);
}
Add After:
function nggv_show_imagebrowser($out, $gid) {
return $out.nggc_voteForm($gid, $buffer);
}
Now we have given access to the function and can paste the following code into “wp-content/plugins/nextgen-gallery/imagebrowser.php”:
<?php echo nggv_imageVoteForm($image->pid); ?>
Conclusion
I’ve tried to explain this in method in a way you can repeat an extend to suit your needs. By following the same logic and tracing the hooks, you can apply this however you might need.
You’ll want to keep “wp-content/plugins/nextgen-gallery/nggfunctions.php” open as a reference for what hooks are available. You can find hooks by searching for “apply_filters(‘”, it will be the first parameter.
Blocking Ads Cross-browser and Save Bandwith Using Your Hosts file
May 26th
Ethics of blocking ads vs. data mining aside, one of the smartest ways I found to block ads is at http://someonewhocares.org/hosts/zero/ where the author, Dan Pollock has compiled a list of urls, with the help of contributors that all redirect to 0.0.0.0 or 127.0.0.1 (localhost, your machine). By appending this list to your current hosts file (or selectively adding parts), whenever your machine attempts to look up a domain name in this list, it will resolved to 0.0.0.0 or your machine. It will never make a request on the internet to the intended server. It will never even download the advertisement.
To take this a step further, you could develop a similar list for your router or DNS server (if you operate it).
I still use adblock plus on top for missed entries.
Creating Named Widgets in WordPress Made Simple
May 16th
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>'; } ?>RabbitVCS is the new Nautilus SVN
May 4th
I should have written about this months ago. Readers have replied to my previous post about nautilus svn, which I claimed to be the first that didn’t suck. This is the evolution of it, RabbitVCS (Version Control System), which aims to use the same intuitive, integrated gui for other version control systems, such as git (check the rabbitvcs roadmap for details on expected support for different versioning system.


