Topic: Link to specific image when gallery is embedded in a page?

Is it possible? I have a gallery embedded in a page and would like to have links that open this page with the gallery open to specific images. I read this in another post:

"To load a gallery at a specific image, use the 'firstImageIndex' config option . You can use PHP or similar to grab the index from the query string and write it to the javascript embed tag." - does this apply in this case? If so, can you help me to make sense of it?

Re: Link to specific image when gallery is embedded in a page?

Yes it is possible to link to a specific image by using the 'firstImageIndex' option. Either set it in the gallery.xml or as a flashvar in the embed code.

Felix Turner
SimpleViewer Support Team.

Re: Link to specific image when gallery is embedded in a page?

Alternatively you could use SWFAddress such as this example.

Mike Richards
SimpleViewer Support Team.

Re: Link to specific image when gallery is embedded in a page?

Sorry, I'm coming from a bit of a knowledge defecit. Is there a "firstImageIndex" how-to for dummies out there somewhere? I'm not sure I understand how it works. Does it mean creating a separate .html file for each image in the gallery? What exactly do I add/change in the code? Thanks!!

Re: Link to specific image when gallery is embedded in a page?

Machepap,
 
I wanted to do exactly what you want to do: use a URL to open a gallery at a specific image.  And like you, I found the knowledge base here to be somewhat lacking.  So I went searching the internet, learned a few things about coding, and came up with a solution.  Here's what I did (this is using SimpleViewer 2.0)

I had the simpleviewer embedded into an html file (in my case it was called highlands.html) which I changed using a text editor to highlands.php

Then in the simpleviewer head, which looks like this:

<!-- SIMPLEVIEWER HEAD. Paste this into the head of the HTML page-->


<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/swfobject/2.2/swfobject.js"></script>


<script type="text/javascript">

var flashvars = {};
flashvars.galleryURL = "gallery.xml";
var params = {};
params.bgcolor = "000000";
params.allowfullscreen = true;
params.allowscriptaccess = "always";
swfobject.embedSWF("simpleviewer.swf", "flashContent", "779", "470", "9.0.124", false, flashvars, params);

</script>

I added the following lines of php code into the head:

<?php
//set $id 's value to whatever is contained on the url.
$id = $_GET['id'];
?>

flashvars.firstImageIndex = <?echo("$id")?>;

So now the final simpleviewer head looks like this:

<!-- SIMPLEVIEWER HEAD. Paste this into the head of the HTML page-->
<?php
//set $id 's value to whatever is contained on the url.
$id = $_GET['id'];
?>

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/swfobject/2.2/swfobject.js"></script>


<script type="text/javascript">

var flashvars = {};
flashvars.galleryURL = "gallery.xml";
flashvars.firstImageIndex = <?echo("$id")?>;
var params = {};
params.bgcolor = "000000";
params.allowfullscreen = true;
params.allowscriptaccess = "always";
swfobject.embedSWF("simpleviewer.swf", "flashContent", "779", "470", "9.0.124", false, flashvars, params);

</script>

In other words, I used the php GET command to pull the variable "id" from the URL, then I used the ECHO command to pass this variable to the firstImageIndex.  Now, to set the image I want to start at, I simply add "?id=x" to the URL, where x is the index of the image you want to start on.  For example:

http://www.joshuacripps.com/galleries/t … s.php?id=0  will start on the first image in the gallery.

http://www.joshuacripps.com/galleries/t … .php?id=10 will start on the 11th image in the gallery.

It ended up being a pretty straightforward solution in the end, once I understood how the code was working.  Hope this makes sense and helps you out!

Josh

Re: Link to specific image when gallery is embedded in a page?

Josh, thanks so much for posting this thorough explanation! Looking over everything you posted here, I can tell that not only will this help me to create the functionality I'm looking for, it will also help me to better understand php! Thank you thank you!

Re: Link to specific image when gallery is embedded in a page?

oops.  i just discovered two minor glitches with doing things this way:

1) You have to put a ?id= on the end of every URL otherwise you will get a "Simpleviewer requires flash . . . blah blah blah" error.  In other words, if you just use http://www.mysite.com/gallery.php, you will get the error.  If you want the gallery to start at the beginning, you have to use http://www.mysite.com/gallery.php?id=0

2) I noticed that any time I have the gallery start on an image which is not the first image, the first image doesn't preload.  I have no idea why not.  Time for some more searching in the forums!  If I find a solution I will post it here.

Josh

Re: Link to specific image when gallery is embedded in a page?

great, thanks!

Re: Link to specific image when gallery is embedded in a page?

joshuacripps wrote:

oops.  i just discovered two minor glitches with doing things this way:

1) You have to put a ?id= on the end of every URL otherwise you will get a "Simpleviewer requires flash . . . blah blah blah" error.  In other words, if you just use http://www.mysite.com/gallery.php, you will get the error.  If you want the gallery to start at the beginning, you have to use http://www.mysite.com/gallery.php?id=0

2) I noticed that any time I have the gallery start on an image which is not the first image, the first image doesn't preload.  I have no idea why not.  Time for some more searching in the forums!  If I find a solution I will post it here.

Josh



Ok, Felix posted a solution to issue #2.  It's a very simple fix; simply set 'thumbPreloading' to 'PAGE' and this should fix the issue.  One other thing to note: the thumbnail will appear dark until you click on it unless you also set 'imagePreloading' to 'PAGE' as well.

Josh

Last edited by joshuacripps (2010-02-19 23:27:13)