• Resolved tara_irvine

    (@tara_irvine)


    I was wondering what would be the best way to complete this..

    I have a thumbnail custom field on every post, and they display in a div perfectly. However, the number of posts is going up so I want to only have 12 thumbnails in one div, and a link at the bottom showing another div with another 12 thumbnails and so on, with next and previous links included.

    The code so far for my custom fields are ..

    <div id="thumbnailsbox" class="thumbnails" style="display:block;padding:0;margin:0;">
    
        <?php foreach($lastposts as $post) : setup_postdata($post);?>
    
     <?php $imgThumb = get_post_meta($post->ID,'img_thumb', true); ?>
    
        <?php if($imgThumb !=""){ ?>
    
        <a>" title="<?php the_title(); ?>"><?php echo "<img class='thumb' src='$imgThumb'/>" ?></a>
    
        <?php } else { echo ''; } ?>
        <?php endforeach; ?>
        <?php endwhile; else: ?>
        <?php _e('Sorry, no posts matched your criteria.'); ?>
        <?php endif; ?>
    
      </div>
      <!-- close thumbnails-->

    I’ve been struggling with this for a while, and I’d really like to nail this, so any help would be awesome!

    xo

Viewing 8 replies - 1 through 8 (of 8 total)
  • maybe (I don’t know, I’m a noob =p ) you should use posts_nav_links

    Thread Starter tara_irvine

    (@tara_irvine)

    I don’t know how to stop displaying the thumbnails after a certain number, say 12.

    I just tried to do this…

    <div id="thumbnailsbox" class="thumbnails" style="padding:0;margin:0;">
    
        <?php if (have_posts()) : while (have_posts()) : the_post(); ?>
        <?php  $lastposts = get_posts('numberposts=12&category=5');?>
        <?php foreach($lastposts as $post) : setup_postdata($post);?>
    
        <?php $imgThumb = get_post_meta($post->ID,'img_thumb', true); ?>
    
        <?php if($imgThumb !=""){ ?>
    
        <a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><?php echo "<img class='thumb' src='$imgThumb'/>" ?></a>
    
        <?php } else { echo ''; } ?>
        <?php endforeach; ?>
        <?php endwhile; else: ?>
        <?php _e('Sorry, no posts matched your criteria.'); ?>
        <?php endif; ?>
    
        <a href="#" id="nextimgs">Next</a>
    
      </div>
      <!-- close thumbnails--> 
    
    <div id="thumbnailsbox2" class="thumbnails" style="display:none;padding:0;margin:0;">
    
        <?php if (have_posts()) : while (have_posts()) : the_post(); ?>
        <?php  $lastposts2 = get_posts('numberposts=12&category=5');?>
        <?php foreach($lastposts2 as $post) : setup_postdata($post);?>
    
        <?php $imgThumb = get_post_meta($post->ID,'img_thumb', true); ?>
    
        <?php if($imgThumb !=""){ ?>
    
        <a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><?php echo "<img class='thumb' src='$imgThumb'/>" ?></a>
    
        <?php } else { echo ''; } ?>
        <?php endforeach; ?>
        <?php endwhile; else: ?>
        <?php _e('Sorry, no posts matched your criteria.'); ?>
        <?php endif; ?>
    
        <a href="#" id="previmgs">Previous</a>
    
     </div>
      <!-- close thumbnails--> 
    
       <script type="text/javascript">
    
    $('#nextimgs').click(function(){
    		$('#thumbnailsbox').hide();
    		$('#thumbnailsbox2').fadeIn();
    	});
    
    $('#previmgs').click(function(){
    		$('#thumbnailsbox2').hide();
    		$('#thumbnailsbox').fadeIn();
    	});
    
    	</script>

    this is the way I want it to work, but the second div should display the NEXT set of thumbnail images.

    not a nice solution, but you could use something like that :

    <div id="thumbnailsbox2" class="thumbnails" style="display:none;padding:0;margin:0;">
        <?php $count = 24; ?>
        <?php if (have_posts()) : while (have_posts()) : the_post(); ?>
        <?php  $lastposts2 = get_posts('numberposts=24&category=5');?>
        <?php foreach($lastposts2 as $post) : setup_postdata($post);?>
        <?php if($count < 13){
        <?php $imgThumb = get_post_meta($post->ID,'img_thumb', true); ?>
    
        <?php if($imgThumb !=""){ ?>
    
        <a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><?php echo "<img class='thumb' src='$imgThumb'/>" ?></a>
    
        <?php } else { echo ''; } ?>
        <?php    } $count--; ?>
        <?php endforeach; ?>
        <?php endwhile; else: ?>
        <?php _e('Sorry, no posts matched your criteria.'); ?>
        <?php endif; ?>
    
        <a href="#" id="previmgs">Previous</a>
    
     </div>

    I think there is a better solution !

    Thread Starter tara_irvine

    (@tara_irvine)

    it works! thank you so much, I know what you mean about a better solution, like what if there are more than 24 custom thumbnails.. Your solution will work tho, so thank-you very much 🙂
    xo

    good 🙂
    (put the topic on “resolved”)

    Thread Starter tara_irvine

    (@tara_irvine)

    well i have a question first, what if there’s only 4 or 5 images for one category? the second div is empty but still the next and previous links work.. sorry to be a pain.

    hum inverse the count variable

    <div id="thumbnailsbox2" class="thumbnails" style="display:none;padding:0;margin:0;">
    $count = 0;
     <?php if (have_posts()) : while (have_posts()) : the_post(); ?>
        <?php  $lastposts2 = get_posts('numberposts=24&category=5');?>
        <?php foreach($lastposts2 as $post) : setup_postdata($post);?>
        <?php if($count > 12){
        <?php $imgThumb = get_post_meta($post->ID,'img_thumb', true); ?>
    
        <?php if($imgThumb !=""){ ?>
    
        <a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><?php echo "<img class='thumb' src='$imgThumb'/>" ?></a>
    
        <?php } else { echo ''; } ?>
        <?php    } $count++; ?>
        <?php endforeach; ?>
        <?php endwhile; else: ?>
        <?php _e('Sorry, no posts matched your criteria.'); ?>
        <?php endif; ?>
    
        <a href="#" id="previmgs">Previous</a>
    
     </div>

    and put a condition on your links …something like if(count > 12)

    [humm, I don’t know if it will work]

    Thread Starter tara_irvine

    (@tara_irvine)

    what worked was I added a $i ==0 then $i ++ after the img was called so it counted the number on the screen.. after that i added a php loop calling the next link when $i >11. works well, thanks for all your help!

Viewing 8 replies - 1 through 8 (of 8 total)

The topic ‘custom fields’ is closed to new replies.