Image Galleries with pMachine

This is my first attempt at a real pMachine tutorial.  This one is basically going to explain how I’ve created the Galleries section here on my site.  I decided to use the “categories” feature of the weblog to allow me to create more than one “gallery” within the same weblog.

I’ll try to make it a “step by step” kind of tutorial, but I make no guarantees.  This tutorial assumes that you are using the “Pro” version of pMachine and will have to create a new weblog.  It also assumes that you have a basic understanding of pMachine and how the various parts (PHP pages, templates, etc.) interact.

Set up the Template

First, you’ll need to create a new template to go along with your Galleries.  In your Control Panel, go to Edit Templates > Create New.  Give it a name such as “galleries” and hit Create New.  We’ll come back and customize the templates later.

Create the Weblog

In the Control Panel, go to Weblog Management > Create New.  Again, give it a name such as “galleries” and hit Create New.  Now, go into the Preferences for your new weblog.  You can see what I put for my preferences (pop-up).

A few things to note:

  1. I’ve decided to put the galleries in a subdirectory off of my main directory.
  2. I changed all of the names of the files.  Only the “Main Weblog page” and “Comments page” settings are really important, since the other two won’t come into play.  Note that the “Comments” file is renamed to view.php.
  3. I set the weblog to use the new Template that was created earlier.
  4. I changed the “Entry Display Order” to display by title.  This is simply personal preference, so any of the settings will work.
  5. I changed the “Entries per Page” to 12.  Again, you can put what you want there.
  6. The rest of the preferences can be left alone or set as you wish.

Create your Categories

Still in your Control Panel, go to Categories and click “Edit Categories” for the weblog you just created.  Here you can add new categories.  Each category will be a set of images—essentially a separate picture album.  Create at least one category.  Here you can see my Categories setup (pop-up).

Create “index.php”

In your “galleries” directory, create a new file called index.php.  I’m using this as sort of a gateway page; a way to allow people to access the different galleries/photo albums.  If you want the file to keep the same look and feel as the rest of your site, you can probably just make it a copy of one of your other files (such as your main weblog file).

(Remember that you’ll need to put a copy of the pm_inc.php file in this directory as well.  Be sure that the path settings inside the file reflect its relative location to the pM script directory.)

Open up index.php for editing.  Where you want the main content—the list of galleries/albums—to go, place this pM tag:

<?php weblog_categories($id,"galleries","text"); ?>

Create “galleries.php”

Also in the “gallaries” directory, create galleries.php.  As before, you can copy an existing file to more easily retain the look and feel of your site.  Open the file for editing.  Where you want the main content—the list thumbnails of the gallery images—to go, place this:

<?php weblog_entries($id,"galleries"); ?>

<div class="spacer">&nbsp;</div>

Create “view.php”

As before, create view.php, copying from an existing file for the look and feel if you like.  Open the file and place these pM tags where the main content goes:

<?php weblog_entry_ind($id); ?>

<h3>Comments</h3>

<?php weblog_comments($id); ?>

<h3>Leave a Comment</h3>

<?php weblog_comment_form($id); ?>

Obviously, you can alter this as needed; it is provided simply as a basis to work from.

Set up the “Multi-Entry” Template

In the Control Panel, go to Edit Templates > galleries > Weblog Multi-entry Templates.  In the first template, Master Date Heading, remove everything.

In the second template, Entries, place the following:

<div class="thumbnail">

<a href="%%comments_url%%" title="%%title%%">%%body%%</a>

</div>

Finally, in the Next/Previous Navigation template, place the following:

<div class="spacer">&nbsp;</div>

<table cellpadding="0" cellspacing="0" border="0" width="90%">
<tr>
<td>%%weblog_prev_page%%</td>
<td align="right">%%weblog_next_page%%</td>
</tr>
</table>

Set up the “Single-Entry” Template

In the Control Panel, go to Edit Templates > galleries > Weblog Single-entry Templates.  Place the following code in the Individual Entry template:

<div class="weblog">

<h3>%%title%%</h3>

%%blurb%%

%%more%%
</div>

Again, you may want to customize this to better fit your page.  The above is very basic and more just an example for you.

Update your Stylesheet

You may have noticed in the “Multi-Entry” template that we used two classes called “thumbnail” and “spacer”.  You’ll need to add these to your stylesheet.  Open your stylesheet in an editor—the sample pMachine site uses the file weblog.css.  In the stylesheet, you’ll need to add the following two styles:

.thumbnail {
border: 1px solid #000;
float: left;
margin: 3px;
padding: 3px;
}

.spacer {
clear: both;
}

The “border”, “margin”, and “padding” are all optional and you can change those as you like.  The important part here is the “float: left;”.  By using this, we’re going to force the thumbnails to display horizontally in a row.  The special thing, though, is that once they run out of room horizontally, they’ll automatically wrap to a new row and keep displaying.  This is one of the main tricks that is going to make your gallery succeed.

The “spacer” style is also needed so that the images don’t spill out of your main content area.

Preparing your Images

We’re almost ready to start adding your images to the gallery.  Before you can do that, though, you’ll need to prepare the images.  Basically, this just means that you’ll need to use some sort of image editing program (Photoshop, Paint Shop Pro, etc.) to create a thumbnail version of each image.

I personally like to just select a portion of each image and use that for the thumbnail.  I also make all of my thumbnails the same size, ragardless of the size of the full-size image.  I make my thumbnails 150px x 150px.  Of course, you can use any size you like and they don’t have to all be the same size, but it’s usually easier and better looking that way.

Creating an Entry

So, now that everything is set up and we have both the images and thumbnails, we can actually go in and create an entry to see how that’s done.  In the Control Panel go to New Entry.  The basics about how a new image is added to the gallery:

  1. The Title holds the title you want to give the image.
  2. Blurb holds the image tag for the main, full-size image.
  3. Body holds the image tag for the thumbnail image.
  4. More holds the description for the image.
  5. For Display In (below “More"), select the “galleries” weblog and the category you want the image to appear in.

Here you can see how I created one of my entries (pop-up).  It’s probably easiest to just use the pMachine File Upload utility to upload your full-size and thumbnail images and have it automatically place the image code in the appropriate box (Blurb or Body).

Hit the “Submit” button and you’ll have your first image in your gallery.

Wrapping Up

You should now have a working Image Gallery.  As mentioned before, you can create new “albums” or groups of images by assigning them to a category.  My own Gallery is a bit more advanced than the one I’ve outlined in this tutorial, but largely it is very much the same.  The main difference on mine is that I have the individual entries/images load into a pop-up window.  Aside from that, the differences are nearly all cosmetic.  You can see my Gallery in action.

Enjoy your new pMachine-powered Image Gallery!

This is an older entry and as such, it may be by a guest author or contain formatting problems / extraneous code. If you notice something wrong with the entry, please use the Contact page to let me know the entry title and issue.

Comments

Hi Chris
thanks for this, I have nearly got my head round it despite only using pM since the 26th.

The one thing that has stopped me in my tracks is the hard coded link in the multi-entry template, which reads:

<div class="thumbnail">

<a href="comments.php?id=114_0_1_0_C” title="%&#xti;tle%%">%&#xbo;dy%%</a>

</div>

I do not understand this, and it does not seem to work.

Cheers and thanks for all the hard work.

Hi

I had the same problem as Julian.

I changed:
<div class="thumbnail">

<a href="comments.php?id=114_0_1_0_C” title="%&#xti;tle%%">%&#xbo;dy%%</a>

</div>

to this:

<div class="thumbnail">
<a href="%&#xco;mment_permalink%%">%&#xbo;dy%% </a>
</div>

and now it works great.

Nic

Oh, wow.  I didn’t even notice that it wasn’t getting rendered correctly.  Nic is quite correct, though I used %&#xco;mments_url%%.

I’ll update the tutorial to display it correctly.

Hello Chris,

I have a quick question to you regarding the category grabbing script: I’d like the script to show a certain text, if “View All” is selected in the category dropdown field and added the following at the end of your scritp - it doesn’t work - no wonder, since I have no idea yet of PHP.

Could you please tell me how to do it? Thank you

if ($catname =="")
{
$catname = “Album: All”;
}
else
{
$catname = “Album: $catname”;
}

...not quite sure why this comment isn’t on the page for the Category Name trick, but oh well…

In the Category Grab script at the top of your file, replace } // END LEAVE THIS with:

} // END LEAVE THIS
else {
$catname = “”;
} // END ELSE

Do you know of anyway to make certain categories member’s only?

So that way some galleries will display only when a specific level of user is logged in?

I’ll investigate more on my end.. but just wondering if you had a good answer.

BlueSun, check out this thread over at the pM forums:
Member Only Categories

I think that should get you started on it.

Ok.. I looked at that recommended reading and worked a solution.  I’m trying to do a member’s only gallery based on the presence of an asterix in the category name but running into problems (thought I should repost here since the category name as gallery is relevant only to your gallery idea)

So if the category name is “My Gallery*”. The Gallery is restricted to level 5 users and above… But if the name of the Gallery is “My Gallery**” I want it restricted to level 6 users and above.

I think I’m having a problem with the use of the asterix in the name as a regular expression and need help to use it as a literal. For example, assuming $catid="Gallery*" or $catid="Gallery**" in the following code, here’s what I did:

---------------code-----------------
$pattern1 = “.+**$”; //Premium Member
$pattern2 = “.+*$”;//Alpha Member

if (eregi($pattern1, $cat_id)) {

if (require_login(5)==0) {

print("You must be a Premium member to access this page.");

}
// else, they’re a member, let them in
else {

weblog_entries($id,"gallery");

}
} //If not, try to match second pattern
elseif (eregi($pattern2, $cat_id)) {

if (require_login(6)==0) {

print("You must be an Alpha member to access this page.");

}
else {

weblog_entries($id,"gallery");

}

} else {

weblog_entries($id,"gallery");

}
?>
-----------------end code------------

Any suggestions on where I messed up?
Thanks in advance

Hi Chris

Im using your tutorial, and its fantastic, Thanks heaps!

I have a problem though, I do not want comments on any of these images.

So, I deleted the content in the Comments templates, but now I am getting this:

Comments
Leave a Comment
<input type="hidden" name="post_id" value="28_0_3_0_C" title=” />

Do you know how I can remove all trace of the comments forms and the tags I am getting in my individual entry when I click on the thumbnail?

Hi Chris

Thanks for solving my comments issue.

I now have another problem.

My Multi Entry (index.php) is not generating the url for the link to the large images.

in multi-entry I have:

<div class="thumb" colspan="2"><a href="%&#xco;mments_url%%" title="%&#xti;tle%%">%&#xbo;dy%%</a></div>

But on my page, it only generates this:

<div class="thumb" colspan="2"><a href=” “ title="another test image"><p>
<img src="http://mawson/~natalie/pmachine/images/uploads/ab.jpg" border="0" alt="image" name="image" width="95" height="95" />
</p></a></div>

see how the a href= is blank?

Do you have any ideas how I can make this work?

fixed it by changing comments_url to comment_permalink as in the above examples.

thanks chris, and thanks everyone else! you all are so helpful!

Hi Chris

Just thought I would let you know that I have slightly modified the way you have laid out the photos and text, to make it easier for others to use the photolog I have created.

Thumbnail goes in Blurb, as its small, and it suits.

Information on the image goes in Body.

Full Size Image goes in MORE.

This seems more logical to me, from an input point of view. A person uploads their thumbnail, enters information about the image, then uploads the full size image.

I find this process flow less confusing and if I havent used the site for a while, I dont have to try and remember where which image goes.

Thanks again for your fantastic tutorial, its really helped me get my head around pMachine!

ps: the other reason I did it this way, was so that I can use the exact same layout for entering text articles, without having to create a new weblog and templates ::))

Chris, could you give me the script for the images in a pop-up window, and when you click the images, the windows will close…

::

Joost

How come I don’t have the “Create New” option.  I only see that option in the pBlocks section.  Did I do something wrong?

Great script Chris! Like Joost I would like to use a pop up screen for the views. Could you send it to me?

Chris,

New pMachine user here - so far I think the app is great.  I am running into one snag, however.  I am using your tutorial as a framework for playing videos instead of showing photos, so the thumbnail creation, etc. works great.  What I’m intending to do is use the thumbnail index as you suggested, use a version of the comments page to display the title, thumbnail (%&#xbl;urb%%), notes about the video (%&#xbo;dy%%), comments from other users in the same page, and a link to the “more” page (renamed PLAY) where the user can watch the video.  I am using this staged display approach since videos can be large and I want the person to see the comments as a way to decide whether to download it or not. 

From a template standpoint you’ve probably noted that I am varying slightly from your tutorial: I am using the %&#xti;tle%% tag to hold the title, %&#xbl;urb%% holds the thumbnail image reference, %&#xbo;dy%% holds a text description of the video, and %&#xmo;re%% holds the video reference & play tags.

SNAG: I initially set things up as you describe, then I change the multi-entry template and single-entry template to use the tags as I outlined above.  When I do so I cannot get the VIEW page (based on comments.php) to use the %&#xmo;re_url%% or %&#xmo;re_link%% variables, e.g. if I do <a href="%&#xmo;re_url%%">PLAY</a> it literally tries to drop the “%&#xmo;re_url%%” into the browser’s address bar, instead of linking to the “More” page (called play.php).  I also notice that the navigation link at the top of the page (by default labeled weblog, using the tag <?php return_to_weblog_or_archives_link($id); ?> points to the video index page (as it should) but with a weird parameter that leaves pMachine “hunting” (what it shows appears to be an incomplete ID, e.g.: http://nimsky.pmachinehosting.com/video/index.php?id=C0_).

Can you shed any light on what might be going on here?

Thanks in advance!
Christian Nimsky

How do I make the fullsize picture appear in a popup window?  Can you make that available as pasrt of the tutorial?

Hi!
I’m trying to build a web gallery wih yout tutorial and everything works fine, except the navigation links:

I placed the tags (php next_weblog_entry($id) etc.) into the code of my “view” page, but the navigation does not “stop” at the end of the chosen category, i.e.: After reaching the last picture of category “a”, there is an unwanted link to the first picture of category “b”

Those tags are not designed to restrict by category.  If you want that functionality, take a look at the Browse by Category add-on by Lynda.

Thanks!!!
After hours of testing I began thinking that I am just too stupid!
Very helpful link!

Hi Chris!

After assembling my gallery using Safari v74 I was surprised to find several other browsers being unable to display the thumbnails on the “galleries” page in the correct position (try your own with IE 5.2.2 for Mac - ok, I know it’s an evil browser, but it DOES exist!).

I found out that the CSS-Style “thumbnail” has to be completed with a “width” tag defining the horizontal size of the picture row you want to create:

.thumbnail {
border: 1px solid #000000;
float: left;
--> width: 400px (or your desired size)
margin: 3px;
padding: 3px;

I hope this information can save other people from despair after hours of work!  wink

Hi Chris:

I’m excited about the images galleries but I am having a problem with getting the thumbnail page to render, and I was hoping you could help.

My image gallery is located at:

http://www.keelydunn.com/galleries/index.php

I’ve created a single entry in the “jo’s shower” category, at:

http://keelydunn.pmachinehosting.com/galleries/galleries.php?id=C0_17_4

You can see that if you hover near the left-hand side of the space, you’re able to click on the thumbnail that isn’t being displayed and the main image is linked to and rendered properly.

I’m thinking this might have to do with the 3-column layout I have set up in my .css file, but I’m really not sure what’s going on. I’d greatly appreciate any assistance you can provide.

- keely

Well, it seems I’ve figured it out. I added two lines to the .thumbnail divclass in my .css:

width: 400px;
position: relative;

..after I realized that other items being rendered in my center block also had the position: relative description. WHEW! /smilies/1cool.gif

...except now that I have the thumbnails being rendered, none of the rest of the php tags are. I’m stumped.

Okay, some progress has been made.

First, with all the floating elements in my .css file, I needed to add a “zdindex= x;” tag to my .thumbnail class. No problem. That helped all the thumbnails to appear in the centre block properly.

Now, the thumbnails in one category do not link properly, but in another they do - sort of. In the “good” category, the URL that appears has extra stuff at the end: “”%20title=” When I remove that manually from the URL, the page is completely correct, including the comment form that wouldn’t display before. In the “bad” category where the link from the thumbnail is broken, that “”%20title=” is all that appears behind the last forward slash - no “view.php?id=....” at all.

I must have screwed something up in the code, but I can’t fathom where. Any ideas?

Hi,

Great tutorial, I had no problems getting it to work. I would like to know if you know of a way when displaying the thumbnails to have them run across the page like 3 or 4 per row and then start a new row, instead of having 1 long running column. It would seem to be more functional in a presentational way. Thanks.

I am a newbie in website designer and programer. I have installed pmachine and want to make galleries as your.

What have I change in pm_inc.php ?
Oricginaly is

$script_directory_path = “./”;

is’t it?

Then what have I change ?

Thank you for your kindness.

Regard,
Indarta

I am a user of your image gallerie. I want to make a page who looks as:
- divide the page in two sides
- left : large pic with the comments below the picture
- right : the tumbs.
- clic the tump and you get a new page with its responding large pic and his comments.

I am traying but not able to make it. Can somebody advise me. Thanks.

Hello Chris,

I am using your image gallerie, Now I have two questions:

1. in some of the tumbnail index pages
(=portfolio and than clicking on links left)
the tumbnail do not apair in strait tows. Some times (see Anke Velstra and Joyce) there is only one tumbnail on the row. Do you know how to correct this?

2. In one of my updates the next or following scipt (and I put it conform your tutorial) is now missing? See the vieuw.php page. I am not able to show it again. Do you know how?

Thanks,
Peter van der Velde

nice job!

Leave Your Comment

Comments may be edited for content or deleted at any time. Civilized discussion is welcome. Anyone spamming, going way off topic, or otherwise being a jerk will probably be deleted or banned.

User Information

pMcode is allowed for comment formatting. pop-up mini reference

Personalization Options

Comment Security