Posted by ljmacphee on September 22, 2008 under coppermine, hack your template, how to, php, wordpress |
Some asked how to add Coppermine photos to WordPress pages. This code will work for any page.
You need to replace MYSQL_SERVER with your database server, localhost usually works just fine.
USER_NAME is the user name for your Coppermine database
PASSWORD is the password for your Coppermine database
DATABASE_NAME is the name of your Coppermine database
Also replace YOUR_DOMAIN with the domain your Coppermine albums are hosted on. You might also need to change the path.
This code will give you a horizontal table of 3 thumbnail photos.
If you are using WordPress, you need to download any page from your theme. Change the file name to Coppermine and the Template name to Coppermine.
Remove the stuff in the middle. On my template that is everything between<div id=”content” class=”page”> and </div> but your template might be different. The past this code into that section being sure to add your password, database etc.
When you are done, upload the new template to your theme directory.
Create a new page and choose Coppermine as the template. All the work is done. You can add text or anything else to the page.
<?php
if ( !($coppermine_db = mysql_connect( “MYSQL_SERVER”, “USER_NAME”, “PASSWORD” ))){
die ( “Can not connect to server” );
}else{
//select db
if ( !(mysql_select_db(”DATABASE_NAME”, $coppermine_db ))){
die ( “Can not select database” );
}
}
//ask mysql db for the path and file name of last five images uploaded
$coppermine_query = “select filepath, filename, ctime from cpg_pictures order by ctime desc limit 3;”;
$coppermine_result = mysql_query($coppermine_query);
$count = mysql_numrows( $coppermine_result );
//start link
$link = “<center>”;
$link .= “<table border=3>”;
$link .= “<th colspan=3><a href=\”http://YOUR_DOMAIN.com/coppermine/\”>Recent Photos</th><tr>”;
$i = 0;
while ( $i < $count ){
$path = mysql_result($coppermine_result, $i, “filepath” );
$name = mysql_result($coppermine_result, $i, “filename” );
$link .= “<td><img src=\”http://YOUR_DOMAIN.com/coppermine/albums/$path” . “thumb_$name\”></td>”;
$i++;
}
$link .= “</tr></table>”;
$link .= “</center>”;
//end link
//clean up
mysql_close();
print $link;
You can see an example of this code TimesToCome where I pull 3 photos from 3 different Coppermine albums onto the page.
Posted by ljmacphee on August 18, 2008 under hack your template, how to, php |
While I was building my wonder of me portal page for TimesToCome I thought it’d be neat to add in my twitter stream.
Here is some very simple PHP code to do so. Now I was lazy and I only check for one link in the tweet. 99% of the time that is sufficient. The only thing you need to change is to change the user name from timestocome to your username. Any other changes are optional.
$username = “timestocome”;
$tweets = fetch_rss(’http://twitter.com/statuses/user_timeline/’.$username.’.rss’);
foreach ( $tweets->items as $tweet ){
print “<hr>”;
$twit = ” “.substr(strstr($tweet['description'],’: ‘), 2, strlen($tweet['description'])).” “;
$link = $tweet['link'];
// hack around php null == 0 ugh!
$xtwit = “x” . $twit;
$mark = strpos( $xtwit, “http://” );
if ( $mark > 0 ){ // we have a link in our tweet perhaps more than one
$l = substr ( $xtwit, $mark, strlen($xtwit) );
$l = substr ( $l, 0, strpos( $l, ” ” ));
$full_link = “<a href=\”$l\”>$l</a>”;
$xtwit = str_replace ( $l, $full_link, $xtwit );
$xtwit = substr ( $xtwit, 1, strlen($xtwit));
print “<br><p>$xtwit <a href=\”$link\”>#</a></p>”;
}else{
print “<br><p>$twit <a href=\”$link\”>#</a></p>”;
}
$time = $tweet['pubdate'];
$time = substr( $time, 0, strlen($time)-6);
print ” $time “;
}
Posted by ljmacphee on August 4, 2008 under hack your template, how to, tools |
TimesToCome was once a bleeding edge website. The splash page had a black starry background with a javascript ufo flying around as any self respecting cool website did in the 1990s. Times changed, and animations fell from favor so it went static. Over time the designs changed but the splash page remained just a link list to various sections of the website. TimesToCome was late moving to a blog setup. It is even later in becoming a portal, but better late than never.
RSS feeds can be used to create portals or to being live, current information to your blogs. Magpierss is built into WordPress. So you can easily use it to bring your other blogs rss feeds into your main blog, or to bring breaking news in your subject area to your blog with a custom rss.
TimesToCome was broken up and spread across eight blogs when I modernized it. The portal grabs the rss feeds from all eight blogs using magpierss.
If you need to install magpierss download it and follow the directions in the “INSTALL” file. It was the simplest install of any web software I’ve look at yet.
Be very sure to follow the directions to set up the cache. If you do not then every time the page loads it will grab fresh copies of the feeds slowing it down as well as any sites it is pulling rss feeds from.
Included in magpie are a README file and a cookbook file. Both contain examples of how to use magpierss. You can just cut and paste the examples and change the names to protect the innocent.
If you are pulling a bunch of feeds and using more than the links, be sure to leave lots of white space in your layout. I’m not a design person. The design took me about four times as long to put together as did the code. But it is simple to remember to use large margins and lots and lots of white space to make things legible. I also used the Coppermine script I wrote as a WordPress plugin to bring in three feeds of latest photos to the portal. It breaks up all the text.
So in summery, if you want to build a portal or incorporate live rss into your site use magpierss. If you are using WordPress it is already installed you just need to read the directions.
TimesToCome portal splash page. I refer to it as ‘The Wonder of me page’. ;D
Herself’s Green Things carries just the garden and houseplant blog rss feeds and photos.
Posted by ljmacphee on May 12, 2008 under coppermine, hack your template |

Here is another popular Wordpress Theme ( Blue-Box) I converted to work with Coppermine. You should find it easy to tailor to your needs including adding in advertising to your sidebar. Coppermine Blue-Box WordPress adapted theme