How to add photos from Coppermine to any PHP page
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.
Add A Comment
You must be logged in to post a comment.