Sortable portfolio/gallery

7 posts by 2 authors in: Forums > CMS Builder
Last Post: March 15, 2013   (RSS)

By Jesus - March 12, 2013

Hello,

I'm working on a project with CMS Builder and I'm trying to do a sortable photo gallery/portfolio.

So I created my section, which contains a field name (select) for the categories I'm using for the gallery and the ones I'll sort to display the gallery.

I'll show up to 12 records per page (3 rows / 4 columns). On the header of my php file, I already inserted the code to load the records from my table.

So, my code for the sortable gallery looks like this:

        <!--BEGIN: top filtrable-->
        <ul id="filtrable">
            <li class="current all"><a href="#">Todos</a></li>
            <li class="category-one"><a href="#">Category One</a></li>
            <li class="category-two"><a href="#">Category Two</a></li>
            <li class="category-three"><a href="#">Category Three</a></li>
            <li class="category-four"><a href="#">Category Four</a></li>
        </ul><!--END: top filtrable-->

I know I need to create a FOR statement in order to create links for all possible categories I'm using (this in case I've unlimited categories) or just create each link myself for limited categories (which its my case at this point). My current select field has 7 categories at this time.

1st thing. Any chance to get some help in order to create this links myself (limited categories)?

I was thinking something like this:

    <?php foreach ($paquetes_lunamielerosRecords as $record): ?>

            <article data-id="<?php echo htmlencode($record['num']) ?>" data-type="<?php echo $record['categoria'] ?>" class="span3">
                <img src="<?php echo $upload['urlPath'] ?>" width="<?php echo $upload['width'] ?>" height="<?php echo $upload['height'] ?>" alt="" />
                <div>
                    <a href="<?php echo $upload['urlPath'] ?>" class="p-view" data-rel="prettyPhoto"></a>
                    <a href="<?php echo $record['_link'] ?>" class="p-link></a>
                </div>
            </article><!--END: latest blog col 1 -->
        <?php endforeach ?>

I'm trying to display: A small image with a link and a prettyphoto image effect in order to display a bigger image if need it. The link will open a regular html page with a a regular text description. I think I still have a problem to select the small image and the bigger image. As I'm not seeing the difference between the code on both cases.

My small image is: <?php foreach ($record['imagen_promo'] as $index => $upload): ?>

My larger image is: <?php foreach ($record['imagen_paquete'] as $index => $upload): ?>

As I didn't include those for statements in my code, I think I'm missing this. I need help to clarify this particular situation between those 2 images and how can I include this for statements in my code.

Also, is it possible to receive some help in order to check my code, but specially to get the proper code in order to get the sortable gallery options working?

Thanks in advance and I'm truly in love with the amazing product!

Jesus

By gregThomas - March 13, 2013

Hi Jesus,

So for the first question you have drop down list field that contains categories,  and you want to be able to filter them? The is probably the easiest way to do this:

<ul id="filtrable">
  <li><a href="?">All</a></li>
  <?php foreach (getListOptions("myTable", "category") as $value => $label):?>
    <li><a href= "?category=<?php echo $value;?>"><?php echo $label;?></a></li>
  <?php endforeach ?>
</ul>

This is just example code, so you'll need to change the variables to get it to work (specifically those highlighted in green). 

The getListOptions function will retrieve the possible list options for a field in an array. Then the foreach loop cycles through them, then links are created for each item.

To use these links as filters, you would need to retrieve your records using the getRecords function, and have allowSearch set to true:

  list($campaign, $campaignsMetaData) = getRecords(array(
    'tableName'   => 'blogs',
    'loadUploads' => true,
    'allowSearch' => true,
    'limit'       => '1',
  ));

Your close on what you need to do to cycle through your uploaded images for each record, I think you need to do something like this:

<?php foreach ($paquetes_lunamielerosRecords as $record): ?>
  <article data-id="<?php echo htmlencode($record['num']) ?>" data-type="<?php echo $record['categoria'] ?>" class="span3">
      <?php foreach ($record['imagen_paquete'] as $index => $upload): ?>
        <img src="<?php echo $upload['urlPath'] ?>" width="<?php echo $upload['width'] ?>" height="<?php echo $upload['height'] ?>" alt="" />
      <?php endforeach; ?>
      <div>
        <?php foreach ($record['imagen_promo'] as $index => $upload): ?>
          <a href="<?php echo $upload['urlPath'] ?>" class="p-view" data-rel="prettyPhoto"></a>
        <?php endforeach; ?>
          <a href="<?php echo $record['_link'] ?>" class="p-link"></a>
      </div>
  </article><!--END: latest blog col 1 -->
<?php endforeach ?>

So each of the $paquetes_lunamielerosRecords records will have two arrays of images associated with it; imagen_promo and imagen_paquete. So I'm cycling through each image using a foreach loop. Then outputting the contents of the URL path of each upload.

If you would like, you can attach/post your code into a post and I can take a look over it for you and make some quick suggestions.

Let me know if you have any questions. 

Thanks!

Greg

Greg Thomas







PHP Programmer - interactivetools.com

By Jesus - March 14, 2013

Hi Greg.

Awesome!!! Let me work during the afternoon on this and will et you know how it goes!

Jesus

By Jesus - March 14, 2013

Hi Greg,

So far so good, we're almost there.

Just something its not working fine with the Sortable option, it displays perfectly the categories but, while checking the generated code it looks like this:

<!--BEGIN: top filtrable-->
<ul id="filtrable">
  <li><a href="?">All</a></li>
      <li><a href= "?categoria=Exóticas">Exóticas</a></li>
       <li><a href= "?categoria=Romance">Romance</a></li>
       <li><a href= "?categoria=Eco Aventura">Eco Aventura</a></li>
       <li><a href= "?categoria=Tradicionales">Tradicionales</a></li>
       <li><a href= "?categoria=Circuitos">Circuitos</a></li>
       <li><a href= "?categoria=Cruceros">Cruceros</a></li>
       <li><a href= "?categoria=Cultural">Cultural</a></li>
</ul><!--END: top filtrable-->

and the code to call each article looks like this:

<!--BEGIN: latest blog col 1 -->
    <article data-id="5" data-type=" Romance " class="span3">
      <img src="/paquetes-lunamieleros/images/uploads/v_puntacana.jpg" width="270" height="200" alt="" />
       <div>
        <a href="/paquetes-lunamieleros/images/uploads/p_puntacana.jpg" class="p-view" data-rel="prettyPhoto"></a>
        <a href="/paquetes-lunamieleros/verArticulo.php?Paquete-de-luna-de-miel-en-Punta-Cana-5" class="p-link"></a>
       </div>
    </article><!--END: latest blog col 1 -->

    <article data-id="4" data-type=" Exóticas " class="span3">
      <img src="/paquetes-lunamieleros/images/uploads/v_islasmaldivas.jpg" width="270" height="200" alt="" />
        <div>
         <a href="/paquetes-lunamieleros/images/uploads/p_islasmaldivas.jpg" class="p-view" data-rel="prettyPhoto"></a>
         <a href="/paquetes-lunamieleros/verArticulo.php?Paquete-de-luna-de-miel-Islas-Maldivas-4" class="p-link"></a>
        </div>
     </article><!--END: latest blog col 1 -->

    <article data-id="3" data-type=" Tradicionales " class="span3">
       <img src="/paquetes-lunamieleros/images/uploads/v_orlando.jpg" width="270" height="200" alt="" />
         <div>
          <a href="/paquetes-lunamieleros/images/uploads/p_orlando.jpg" class="p-view" data-rel="prettyPhoto"></a>
          <a href="/paquetes-lunamieleros/verArticulo.php?Paquete-de-luna-de-miel-en-Orlando-3" class="p-link"></a>
        </div>
     </article><!--END: latest blog col 1 -->

    <article data-id="2" data-type=" Exóticas " class="span3">
       <img src="/paquetes-lunamieleros/images/uploads/v_isladehamilton.jpg" width="270" height="200" alt="" />
          <div>
           <a href="/paquetes-lunamieleros/images/uploads/p_isladehamilton.jpg" class="p-view" data-rel="prettyPhoto"></a>
           <a href="/paquetes-lunamieleros/verArticulo.php?Paquete-de-luna-de-miel-en-la-Isla-de-Hamilton-2" class="p-link"></a>
        </div>
     </article><!--END: latest blog col 1 -->

The sortable thing its not working. What I'm seeing its that the category name on the sortable area looks like this: ?categoria=Exóticas and on the article looks like this  Exóticas (with some spaces too).

Any ideas on how to remove the ?categoria= part from the sortable area and/or to remove the spaces below?

Thanks for pointing me to the right direction!

Jesus

By Jesus - March 14, 2013

I found the way to remove the ?categoria= from the code, so now that's fixed.

Still trying to get the sort to work as I'm still seeing some spaces and probably that's causing the issue. Checking....

By gregThomas - March 15, 2013

Morning Jesus, 

I think your category links might not be filtering the categories because you don't have allowSearch set to true in your getRecords function. I would check that allowSearch is set to true in it: 

    'allowSearch' => true,

You can remove the white spaces from your data tags using the PHP trim function:

 <article data-id="<?php echo htmlencode($record['num']) ?>" data-type="<?php echo trim($record['categoria']) ?>" class="span3">

The trim function (http://php.net/manual/en/function.trim.php) is used to remove any white spaces at the beginning and end of strings.

Thanks!

Greg

Greg Thomas







PHP Programmer - interactivetools.com