This is my setup:
* A Wordpress (v. 2.2 I think) powered blog. Most of my site is made up of pages created through Wordpress
* A Coppermine photo gallery. I use Coppermine to display the images that I give away as stock photos. My version is 1.4.11.
These two sites are not integrated very well, though I have links that connect them.
Because I am running a stock photo site I want the pictures from my Coppermine gallery to show up on my homepage (powered by Wordpress) and I want them to be random. I also want top viewed or other types of photos to show up.
After trying to figure out how to do this myself I found CPMFetch.
Here is an example of what CPMFetch can do on a Wordpress page:

Unfortunately, it takes a long time to get this kind of stuff working when you aren’t a website development guru. I am definitely not a website guru…
This post details some of the problems I have had with integrating Coppermine with Wordpress.
When I first installed Coppermine at week 1 of this little trek I am on I made a mistake and pointed my install path for the gallery at
www.therightpic.com/public_html…
which effectively screws up your filepath, since www.therightpic.com and public_html represent the same place.
I did not notice this at the time because the picture database worked just fine on it’s own.
One month later I was ready to begin integrating the two sites and I found CPMFetch and decided I wanted to try and incorporate it with my Wordpress powered blog.
I followed the simple download and install procedure documented at http://cpmfetch.fistfullofcode.com/ and Voila! Nothing worked.
The install is pretty easy. You point your browser at a certain PHP page for CPMFetch and it finds your folder and you are done.
It also grabs a few of your pics and displays them for you if everything is working OK. That was the problem.
At the top of the installation finished screen I got:
CF-Error CF-Error CF-Error CF-Error CF-Error
and then the names of a few of my pictures and little blue boxes but no images.
To make this long description a little shorter I went to the CPMFetch forums (which are part of the Coppermine forums) and was told that I was an idiot.
Well, actually was told that I had my path screwed up for Coppermine. If anyone reading this has the same type of errors and wants some help respond below and I will try to help you out.
I removed the public_html from my page and somehow had lost a bunch of my pictures (thanks to one of the other things I tried) and had to reload them. I have not had time to do anything else with the links which means that a lot of the links for medium and high res versions and keywords are gone temporarily.
After reloading all of the pics I was ready, or so I thought. I started putting the PHP code from CPMFetch in my Wordpress posts and pages but it did not work.
After some research I found out that Wordpress does not have native support for PHP, which is the language that CPMFetch uses. Argghh.
I then tried to find some people on the Internet who had created some kind of Coppermine / Wordpress integration code that would make all of it magically work together and found a few things, none of which seemed to work very well.
I then stumbled onto a PHP integration plugin called runPHP on the Wordpress plugin website and installed it. It is written by James Van Lommel and is easy to install and simple to configure.
Once I got it set up a picture showed up on the home page! One lonely little picture, which was a giant step for me.
The next hurdle I ran into was getting the syntax correct for the CPMFetch commands. If you are unfamiliar with programming, CPMFetch can be a little daunting. Here is some of the code that I am using on my homepage:
There may be easier ways to do these things but this is working for me and you may be able to modify it and put it on your own pages and make it work for you:
<?php
include_once "./cpg1.4.11/cpmfetch/cpmfetch.php";
$statsCpm = new cpm("./cpg1.4.11/cpmfetch/cpmfetch_config.php");
echo "Here are some of the ";
$statsCpm->cpm_listMediaCountFrom("");
echo " free photos and images in our gallery";
?>
This displays:

What is cool about this is that the 440 number automatically adjusts itself as I add pictures to my Coppermine photo gallery.
The first couple of lines:
<?php include_once "./cpg1.4.11/cpmfetch/cpmfetch.php";
start your PHP code and then enable CPMFetch to work on the page. Any place on your page you want to add pictures put the <?PHP command before your actual CPMFetch code.
The line that starts with ‘include_once’ is only needed on the web page once, as far as I can tell. I can put multiple pictures anywhere else on my page and don’t need this line, as long as I have it at the top of my page somewhere.
The next line:
$statsCpm = new cpm("./cpg1.4.11/cpmfetch/cpmfetch_config.php");
says that I want to use CPMFetch and create a new object with it. Don’t get confused and don’t overthink it. Any time you want to put a picture or a statistic from your Coppermine gallery on the page start with the <?PHP tag and then add a line that looks like this. Start with the dollar sign for sure and then name it whatever you want.
It could be:
$printgallerytotals = new cpm("./cpg1.4.11/cpmfetch/cpmfetch_config.php");
or
$showmystuff = new cpm("./cpg1.4.11/cpmfetch/cpmfetch_config.php");
or
$thecircusisintown = new cpm("./cpg1.4.11/cpmfetch/cpmfetch_config.php");
it does not matter what you call the object, just use a dollar sign and then put a name. You are actually making a PHP variable. If you want more info on this do a search for PHP variables on Google.
After your dollar sign variable and the equals sign you are saying you want a new CPMFetch object. You might as well be saying ‘Use CPMFetch here.’
Your path might be different than mine. The path is the part in the parentheses. I can give more info on this if needed but the CPMFetch manual is fairly good at explaining this so I will skip it unless someone wants more help.
You will have this line everywhere that you want to use CPMFetch.
I know I am repeating myself. I know I am repeating myself. But these are the problems that I went through as I tried to figure this stuff out.
The next four lines:
echo "Here are some of the ";
$statsCpm->cpm_listMediaCountFrom("");
echo " free photos and images in our gallery";
?>
are a mixture of just normal PHP and CPMFetch stuff.
Any time you write echo “Some words”; inside your PHP tags (<?PHP) you are going to print out on the screen:
Some words
So I started my sentence with “Here are some of the ” and then I used this line:
$statsCpm->cpm_listMediaCountFrom("");
This is our first usage of CPMFetch that is going to do something visible. I repeat the dollar sign and then the name I used when I did my new CPMFetch object line.
Next I do a dash and then a greater than symbol and then I put in the CPMFetch task that I want to do. Check the manual out for different things you can do.
This particular one:
cpm_listMediaCountFrom("");
adds up and prints out the total count of items in your Coppermine photo gallery.
Next I did another echo statement with more text.
Finally, I need to close the PHP statement so that I can get on with my normal HTML.
?>
If I don’t do this I am going to be in trouble because my PHP interpreter will try to read the rest of my page as PHP code and the first HTML bracket I have will throw out an error and your whole page will be jacked up, to put it scientifically.
So, look at the whole thing again:
<?php
include_once "./cpg1.4.11/cpmfetch/cpmfetch.php";
$statsCpm = new cpm("./cpg1.4.11/cpmfetch/cpmfetch_config.php");
echo "Here are some of the ";
$statsCpm->cpm_listMediaCountFrom("");
echo " free photos and images in our gallery";
?>
Now, let’s add a randomly chosen photo to another area of the page:
By the way, I put this stuff in a table. There is probably a better way to do it but I am using tables because that is all I know how to do. I am not going to show the HTML, just the CPMFetch stuff.
<?php
$randCpm = new cpm("./cpg1.4.11/cpmfetch/cpmfetch_config.php");
$options = array('imagesize' => 'large');
$randCpm->cpm_viewRandomMediaFrom("" ,1,1, $options);
?>
The first line should look familiar. I started PHP on the first line. I made a new object on the second called $randCpm.
The next couple of lines are new.
$options = array('imagesize' => 'large');
This does a few things. All I really care about is that it tells CPMFetch to display the picture that I want as a large one. Don’t make it a thumbnail or something else, show it at the resolution that I uploaded it at. There are other values instead of ‘large’ and you can find them in the manual and there is a lot of power in the $options.
Next, I actually told it to get a random picture and show it:
$randCpm->cpm_viewRandomMediaFrom("" ,1,1, $options);
This is an important line.
$randCpm->
Nothing new here.
cpm_viewRandomMediaFrom("" ,1,1, $options);
I just told CPMFetch to grab a random picture from my Coppermine gallery and display it using the $options I specified.
I will write more about this later but the “” says to use any picture. The first 1 says to use one column of pictures and the second 1 says to display one row of pictures. With the ,1,1 I have just said that I only want one picture shown. I could have done ,3,2 or ,4,7 or any other combination of rows and columns that I want to show pictures in.
Once I am done with thses few lines and put them in an HTML table every time my page is refreshed it shows a different picture from the gallery.

This smoggy LA sunset is brought to you by Coppermine and CPMFetch.
I will try to write more about this later but CPMFetch is an outstanding tool and if you use runPHP along with it you have a powerful addition to your Wordpress blog.
Notice that I ended the code with my PHP tag: ?>
Somewhere at the end of all of your PHP CPMFetch entries you need to add one other line of code to close your database connection. The creator of CPMFetch says that it will actually work without it but it is a good idea to do it anyway. This is the code:
<?php
include_once "./cpg1.4.11/cpmfetch/cpmfetch.php";
$statsCpm = new cpm("./cpg1.4.11/cpmfetch/cpmfetch_config.php");
echo "Here are some of the ";
$statsCpm->cpm_listMediaCountFrom("");
echo " free photos and images in our gallery";
$statsCpm->cpm_close();
?>
Notice the extra line, $statsCpm->cpm_close();
By using this at the bottom I am saying that I am done using CPMFetch. You only need to use it once, just like you only need to use the include statement once.
0 responses so far ↓
There are no comments yet...Kick things off by filling out the form below.
Leave a Comment