Category Archives: Coding

Picasa2Coppermine Project

I just uploaded to Google Code the source code of Picasa2Coppermine. This makes it possible to add a button in Picasa that when clicked will upload selected files into a Coppermine Photo Gallery running version 1.5. CPG 1.5 has not been officially released yet, so it is only available via subversion checkout.

The ability to import from Picasa to Coppermine is a frequent request and something that I personally really wanted to be able to do. I am excited to have been able to accomplish the basics of the task. However, there is still a lot remaining to be done to make this even better. If you are brave and tech-savvy enough to run a test installation of CPG 1.5 before it is released, and also use Picasa, I would appreciate that you try this out. Code contributions would be greatly appreciated.

Happy Martin Luther King, Jr. Day!

How to Add RSS Feed Link to archive.php for WordPress

archive.php (in the WordPress theme folder) is the file that handles the output of posts grouped by categories, tags (in WP 2.3) and by dates. Since I have a wide variety of topics, I figured it would be helpful to provide feeds specific to a reader’s particular interest(s). The problem was I didn’t know how to do it easily. After playing around with the code, I came up with a solution which turned out to be pretty simple and straightforward. It is probably not perfect but it gets the job done.

Wherever you want to place the link, add this code:

<div>
<a href="feed/">Subscribe to Feed</a>
</div>

So, if you’re interested in my WordPress postings, you can use the link to the feed when viewing the WordPress category.

How to Display All Blog Posts

For reasons I will explain in another post about Linked Custom Search Engines, I wanted to generate a page that would include all of my posts in their entirety. There didn’t seem to be a ready-made solution. I found a plugin but it didn’t show all posts the way I wanted. This is different from the current view where the posts are paginated when there are x number of posts per page.

I came across this support page, displaying postbypost yearly archives, where it game me a good starting point. I learned about The_Loop. I eventually managed to create a page that shows all posts on one page.

I figured I would share the code to help others in a similar situation. All Posts Template file, is a template file to put in the themes folder. Remove the .txt that I had to add to the filename to upload to my blog. Create a new page and choose AllPosts as the template. If you want to minimize duplicate content, add a robots.txt entry for that page. It’s possible to add url parameters so that posts from specific years are displayed: 2007 posts.

How I Create Widgets for WordPress

I haven’t been able to find clear instructions on how to add widgets to WordPress. This widget tutorial for developers was as close as I could get, but it applies to the Widget Plugin before WordPress included Widgets in v 2.2.

I’ve figured out a system that has worked for me. I can’t say that it is the best or only way. It’s just a way for me to accomplish what I want. That’s also why I’m not calling this a how-to.

First, create a new file called widgets.inc.php and place it in the themes folder. Here is an example based on a widget to spread Firefox:

<?php
/* Widgets I added */
	function wp_widget_firefox($args) {
	extract($args);
?>
	<?php if (strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE') !== false) {?>
		<?php echo $before_widget; ?>
		<?php echo $before_title; ?>
		<?php _e('Try Firefox'); ?>
		<?php echo $after_title; ?>
		<ul><li>
			<a href="http://www.spreadfirefox.com/?q=affiliates&id=YOUR_ID&t=210"><img border="0" alt="Firefox 2" title="Firefox 2" src="http://sfx-images.mozilla.org/affiliates/Buttons/firefox2/firefox-spread-btn-1b.png"/></a>
		</li></ul>

		<?php echo $after_widget; ?>
		<?php
		}
		?>
<?php
	} //close function
?>

Now edit /wp-includes/widgets.php.

FIND:

add_action('init', 'wp_widgets_init', 1);

BEFORE it, ADD:

$themes_path = '/home/ABSOLUTE/PATH/TO/BLOG/wp-content/themes';
include("$themes_path" . '/widgets.inc.php');

Edit the path accordingly.

In the wp_widgets_init() function, add these lines for each widget you want to add. Using the Firefox widget example:

$class['classname'] = 'widget_firefox';
wp_register_sidebar_widget('firefox', __('Spread Firefox'), 'wp_widget_firefox', $class);

WordPress Widget: Spread Firefox

I coded a widget to help Spread Firefox via a WordPress widget. Here is the code:

function wp_widget_firefox($args) {
	extract($args);
?>
	<?php if (strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE') !== false) {?>
		<?php echo $before_widget; ?>
		<?php echo $before_title; ?>
		<?php _e('Try Firefox'); ?>
		<?php echo $after_title; ?>
		<ul><li>
			<a href="http://www.spreadfirefox.com/?q=affiliates&id=YOUR_ID&t=210"><img border="0" alt="Firefox 2" title="Firefox 2" src="http://sfx-images.mozilla.org/affiliates/Buttons/firefox2/firefox-spread-btn-1b.png"/></a>
		</li></ul>

	<?php echo $after_widget; ?>
	<?php
	}
	?>
<?php

}

I honestly don’t know if this exact code will work for people because I came up with my own system of creating widgets. However, you should be able to use this as a template if you know how to add widgets to your WordPress blog. Note that the code assumes that it will be in a file that contains other widgets. That’s why the php tags are the way they are.

I wrote the code so that it only shows the widget when the user agent/browser is IE. There’s no point in showing it for people who are already using Firefox, or any other browser for that matter. I don’t like to see things that don’t apply to me.

For example, that DirecTV commercial with Pamela Anderson. She looks at the camera and berates the viewer for not watching her on DirecTV. As a matter of fact, I am using DirecTV. Advertising needs to be smarter than that.

BTW, although the link has affiliate info, Spread Firefox Affiliates don’t make money as with other affiliate programs. For me, I just like to know how I am contributing to the effort.