splitting first image

4 posts by 2 authors in: Forums > CMS Builder
Last Post: May 5, 2012   (RSS)

Re: [loccom] splitting first image

By gkornbluth - April 9, 2012

Hi Locom.

Here's a recipe from my CMSB Cookbook thecmsbcookbook.com that might get you started on working out an answer to your first question. (I'm not sure I understand the second question)

Hope it helps.

Best,

Jerry Kornbluth

COUNTING IMAGES IN A MULTI-IMAGE UPLOAD FIELD

I needed to count the number of images that existed in a multi-image upload field that was the only record in my editor, so that if there was only one image I could display it as an image and if there was more than one image I could display them as a slide show.

I started out with another recipe in the Cookbook called: LIMITING THE NUMBER OF IMAGES ON A PAGE AND SHOWING CODE IF EXCEEDED (just above this one)

The basic approach in that recipe is:
<?php foreach ($home_page_slidesRecords as $record): ?>
<?php $count = 0; ?>
<?php foreach ($record['image'] as $upload): ?>
<?php $count++; ?>
<?php endforeach; ?>
<?php echo $count>1 ? "There is more than one thumbnail" : "There is only one thumbnail" ; ?>
<?php endforeach; ?>

I modified the code so that instead of messages, the required code was inserted into the page. I also added a checkbox field to allow the client to decide if they wanted to use this as a slide show regardless of how many images were uploaded. I also added <?php shuffle($record['images']) ?> to the code to randomize the image displayed when there was no slide show.
<?php foreach ($home_page_slidesRecords as $record): ?>
<?php $count = 0; ?>
<?php foreach ($record['image'] as $upload): ?>
<?php $count++; ?>
<?php endforeach; ?>
<?php if ($count > 1 && $home_page_slidesRecord['slideshow'] == 1): ?>
<div id="show" class="slideshow"></div>
<?php else: ?>
<?php shuffle($record['images']) ?><?php foreach ($record['image'] as $upload): ?><img src="<?PHP echo $upload['thumbUrlPath'] ?>" width="<?PHP echo $upload['thumbWidth'] ?>" height="<?PHP echo $upload['thumbHeight']
?>" alt="" />
<?PHP endforeach ?>
<?php endif ?>
<?php endforeach; ?>

The first CMS Builder reference book is now available on-line!







Take advantage of a free 3 month trial subscription, only for CMSB users, at: http://www.thecmsbcookbook.com/trial.php

Re: [gkornbluth] splitting first image

By loccom - May 5, 2012

Hi

Sorry the delay in responding

I still have the issue.

Thanks for your input, and I managed to make a random strip using the code supplied.

But what I am really looking for is the ability to stagger photos through an article.

The old article manager would allow me to add photos, AM would generate tags for me to distribute through the article.

How can i split photos to distribute, or at least have one photo at the top and other photos at the bottom?

thanks

Re: [steveo] splitting first image

By gkornbluth - May 5, 2012

Here's another recipe that might offer some direction. Hope it helps,

Jerry Kornbluth

DISPLAY A SPECIFIC IMAGE FROM A SPECIFIC RECORD

My client wanted to be able to display a specific image from a group of records and multi image uploads.

I couldn’t get this to work until Chris Waddell from Interactive Tools unlocked the secret.

He said:

If $affiliationsRecords is a list of all your records, then $affiliationsRecords[0] will give you the first record, $affiliationsRecords[1]
will give you the second, etc. It's a little confusing that the counting starts at 0 instead of 1.

$affiliationsRecords[3]['logo'][2] will grab the fourth record ([3]), its list of images (['logo']), and select its third image ([2]).

Since $affiliationsRecords[1]['logo'] refers to the list of images. You need to use $affiliationsRecords[1]['logo'][0] if you want to refer
to a specific image ([0] gives you the first one, etc.)

You’ll need to define a variable for the specific image. To call the 3rd image from the 4th record I used

<?php $myImage = $affiliationsRecords[3]['logo'][2]; ?>

The code that you’d use in the body of your viewer page where you want the image to display would be:

<?php $myImage = $affiliationsRecords[3]['logo'][2]; ?>
<img src="<?php echo $myImage['thumbUrlPath'] ?>" width="<?php echo $myImage['thumbWidth'] ?>" height="<?php echo $myImage['thumbHeight']
?>" alt="" />

You can also define other variables, like this one for the link to a detail page relating to the same record:

<?php @$mylink = $affiliationsRecords[4]['_link']; ?>

Then the code including a linked image might look like this:

<?php @$myImage = $affiliationsRecords[3]['logo'][2]; ?>
<?php @$mylink = $affiliationsRecords[3]['_link']; ?>
<a href="<?php echo $mylink ?>"><img src="<?php echo $myImage['thumbUrlPath'] ?>" width="<?php echo $myImage['thumbWidth'] ?>"
height="<?php echo $myImage['thumbHeight'] ?>" alt="" border="0"/></a>

The first CMS Builder reference book is now available on-line!







Take advantage of a free 3 month trial subscription, only for CMSB users, at: http://www.thecmsbcookbook.com/trial.php