Herself's Webtools

Scripts, HowTos, Templates, Plugins, Widgets, Tips

Archive for January, 2008

Cutline 3 column template for Coppermine

with 5 comments

I’ve been using Coppermine about 3 months now. While it has some shortcomings I’m mostly pleased with it. There are hundreds of templates available for Coppermine, but most of them seem to be written for young men. I needed something a bit cleaner, brighter and that would blend in with my blogs.

Then I ran across and excellent tutorial by Gizmo about Converting a WordPress theme to a Coppermine theme. A couple of hours later I had a Cutline theme for Coppermine. Several more hours later I had worked out the bugs and polished it a bit.

You can see it On my personal blog photo section.

Read the readme file first and customize the theme for your website. Then just upload it to your Coppermine/themes directory. Go into your admin menu and to themes and change the theme.
Cutline Theme for Coppermine

Written by Linda MacPhee-Cobb

January 31st, 2008 at 5:00 am

How to convert your WP Plugin to a WP Widget

without comments

I was asked to convert a WordPress plugin of mine to a WordPress widget. It turned out to be a simple process but simple directions were lacking.

You can find examples of widgets as they are meant to be written at the end of the /wordpress/wp-includes/widgets.php file. Use those examples as your template should you have any questions.

Below is a skeleton of a WP Widget. All necessary parts are in this file, all unnecessary ones are not. Start with this and just plunk your plugin code in the section indicated in the comments.


<?php/*
Plugin Name: Your Plugin/Widget Name goes here
Version: 1.0
Plugin URI: The plugin webpage for help and more information
Author: Your name
Author URI: Your homepage
Description: Description of widget
*/
// all functions go in this function this is your main
function your_very_unique_widget_name_badge_init() {
//gracefully fail if sidebar gets deactivated
if ( !function_exists(‘register_sidebar_widget’) )
return;
//the code specific to your widget goes in this function
function your_very_unique_widget_name_badge($args)
{ //fetch theme related things
extract($args); // this information is from what the user input in our control function below
$options = get_option ( ‘your_very_unique_widget_name_badge’ );
$title = $options['title'];

// this is where your plugin code belongs all your mysql and php statements go here…….
// ……………………..
// ………………………

//output to sidebar beginning of widget output
echo $before_widget;
echo $before_title;
echo $title;
echo $after_title;

// pretty up and ready the output from your plugin here

//now print output to webpage
echo “<br> $output <br>”;

//clean up – close db if opened etc here

return $output;

}

//user options Be very sure to at least include the option to change the title
// the other stuff is just to show you how to use the checkbox

function your_very_unique_widget_name_badge_control()
{
$options = get_option ( ‘your_very_unique_widget_name_badge’ );

//set initial values if empty or else fetch current
if ( ! is_array($options) ){

$options = array( ‘title’=>”Default Widget Title”, ‘random’=>”0″ );
}else{
//fetch existing choices from user selected options
$title = $options['title']; // title to show in sidebar
$random = $options ['random'] ? ‘checked=”checked”‘ : “”; // ? yes/no ?
}

//clean up and post
if ( $_POST['your_very_unique_widget_name_badge-submit'] ) {

//title
$options['title'] = strip_tags(stripslashes($_POST['your_very_unique_widget_name_badge-title']));

//yes or no selection box example
$options['yes'] = isset($_POST['your_very_unique_widget_name_badge-yes'] );

//save user selections
update_option(‘your_very_unique_widget_name_badge’, $options);

}

// This is the form where we collect the user preferences
// Notice that we don’t need a complete form. This will be embedded into the existing form.

echo ‘<p style=”text-align:right;”><label for=”your_very_unique_widget_name_badge-title”>’ . __(‘Title:’) . ‘ <input style=”width: 200px;” id=”your_very_unique_widget_name_badge-title” name=”your_very_unique_widget_name_badge-title” type=”text” value=”‘.$title.’” /></label></p>’;

echo ‘<p style=”text-align:right;”><label for=”your_very_unique_widget_name_badge-yes”>’ . __(‘Check for random images’) . ‘ <input style=”width: 20px;” id=”your_very_unique_widget_name_badge-random” name=”your_very_unique_widget_name_badge-random” type=”checkbox” value=”‘.$random.’” /></label></p>’;

//Input our form info if user presses save button
echo ‘<input type=”hidden” id=”your_very_unique_widget_name_badge-submit” name=”your_very_unique_widget_name_badge-submit” value=”1″ />’;

}

//register widget so it is available to user in widget page
register_widget_control(array(‘Your Widget Name’, ‘widgets’), ‘your_very_unique_widget_name_badge_control’, 300, 150);

<//register control panel so use can see it and use it
register_sidebar_widget(array(‘Your Widget Name’,'widgets’), ‘your_very_unique_widget_name_badge’);

}

// go to main
add_action(‘widgets_init’, ‘your_very_unique_widget_name_badge_init’);
?>


Written by Linda MacPhee-Cobb

January 28th, 2008 at 5:00 am

Posted in how to,wordpress