merge testimonials and retain MetaData for next and previous

2 posts by 2 authors in: Forums > CMS Builder
Last Post: January 14, 2013   (RSS)

Hi Zick,

Is there any particular reason to merge the metadata into one array? If your displaying the same number of items from each getRecords function, could you use the page numbers from any of the metaData arrays. Maybe do something like this:

   // get records
  $testimonialMerge = array();

    // load project_showcase records
      list($project_showcaseMergeRecords, $project_showcaseMergeMetaData) = getRecords(array(
        'tableName'   => 'project_showcase',
          'allowSearch' => '0',
        //'perPage'     => '2',
    ));
    
    // load records from 'replacement_projects'
      list($replacement_projectsMergeRecords, $replacement_projectsMergeMetaData) = getRecords(array(
        'tableName'   => 'replacement_projects',
          'allowSearch' => '0',
        //'perPage'     => '2',
    ));
    
    // load records from 'testimonials'
      list($testimonialsMergeRecords, $testimonialsMergeMetaData) = getRecords(array(
        'tableName'   => 'testimonials',
          'allowSearch' => '0',
        //'perPage'     => '2',
    ));
    
    $testimonialMerge = array_merge($project_showcaseMergeRecords, $replacement_projectsMergeRecords, $testimonialsMergeRecords);
    $testimonialMerge = array_merge($project_showcaseMergeMetaData, $replacement_projectsMergeMetaData, $testimonialsMergeMetaData);

<div class="photo-next-previous-container"> 
<!-- previous next -->
<h4 style="font-size:15px"><strong><?php if ($testimonialMergeMetaData['prevPage']): ?>
      <a href="<?php echo $testimonialMergeMetaData['prevPageLink'] ?>">Previous</a>
    <?php else: ?>
    <span style="font-size:15px; color:#999">Previous</span>
    <?php endif ?> 

<?php if ($testimonialsMergeMetaData['nextPage']): ?>
      <a href="<?php echo $testimonialsMergeMetaData['nextPageLink'] ?>">Next</a>
    <?php else: ?>
    <span style="font-size:15px; color:#999">Next</span>
    <?php endif ?>
    
<?php  
    if (@!$_GET['page']): $current_page = "1"; 
    else: $current_page = $_GET['page'];    
    endif;  ?> 

<?php foreach (range(1,$testimonialMergeMetaData['totalPages']) as $page): ?>  
  <?php if ($page == $current_page): ?> 
     <strong><?php echo $page; ?></strong> 
<?php else: ?> 
     <a href="?<?php echo http_build_query(array_merge($_REQUEST, array( 'page' => $page ))) ?>"><?php echo $page; ?></a> 
<?php endif ?> 
<?php endforeach; ?>
</strong></h4>
<!-- /previous next -->
</div>

<ul class="testimonial-photo-galley-column"><!-- testimonial-photo-galley-column -->
<?php foreach ($testimonialMerge as $record): ?>
<?php if ($record['customer_photo']): ?> 
        <?php foreach ($record['customer_photo'] as $upload): ?>
        
<li class="box1"><!--Repeating list item-->
<div class="testimonial-photo-galley-block">
    <div class="testimonial-photo-galley-cell-border">
    <div class="testimonial-photo-galley-cell">
    <a href="<?php echo $record['_link'] ?>"><img src="<?php echo $upload['thumbUrlPath'] ?>" alt="" width="<?php echo $upload['thumbWidth'] ?>" height="<?php echo $upload['thumbHeight'] ?>" class="testimonial-photo-galley-images" /></a>
    
    <div class="testimonial-photo-captions">
    <h4><a href="<?php echo $record['_link'] ?>">
    <strong><?php echo $record['customer_name'] ?></strong></a></h4>
    <p><?php echo $record['customer_testimonial'] ?></p><?php if ($record['hide_learn_more'] == '0'): ?><p style="padding-top:12px; font-weight:bold; text-transform:uppercase"><a href="<?php echo $record['_link'] ?>">Learn More</a></p><?php endif ?>
    <!-- /testimonial-photo-captions--></div>
    
    <!-- /testimonial-photo-galley-cell --></div>
    <!-- /testimonial-photo-galley-cell-border --></div>
<!-- /testimonial-photo-galley-block --></div>
<!--/Repeating list item--></li>
<?php endforeach ?>  
<?php elseif ($record['customer_testimonial']): ?> 
<li class="box2"><!--Repeating list item-->
<div class="testimonial-nophoto-galley-block">
    <div class="testimonial-nophoto-galley-cell-border">
    <div class="testimonial-nophoto-galley-cell">
    <div class="testimonial-nophoto-captions">
    <h4><a href="<?php echo $record['_link'] ?>">
    <strong><?php echo $record['customer_name'] ?></strong></a></h4>
    <p><?php echo $record['customer_testimonial'] ?></p><?php if ($record['hide_learn_more'] == '0'): ?><p style="padding-top:12px; font-weight:bold; text-transform:uppercase"><a href="<?php echo $record['_link'] ?>">Learn More</a></p><?php endif ?>
    <!-- /testimonial-photo-captions--></div>
    
    <!-- /testimonial-photo-galley-cell --></div>
    <!-- /testimonial-photo-galley-cell-border --></div>
<!-- /testimonial-photo-galley-block --></div>
<!--/Repeating list item--></li>

<?php endif ?>
<?php endforeach ?>
<!-- /testimonial-photo-galley-column --></ul>

I'm not so sure what you can do about the total pages. Will you have the same number of records in each section? Or do the quantites vary? 

Thanks!

Greg

Greg Thomas







PHP Programmer - interactivetools.com