Support » Fixing WordPress » Custom Post Type and class

  • Resolved alex05


    Hello guys !

    I’m developing a “gallery” page and i’m using a custom post type, then for the gallery custom post type i’ve add custom metaboxes and everything is working but i’ve got a little problem…

    here is the code i’m using to display my gallery entries

    <?php $loop = new WP_Query( array( 'post_type' => 'gallerylist', 'posts_per_page' => 100 , 'order' => 'ASC', 'paged'=>$paged ) ); ?>
    <?php while ( $loop->have_posts() ) : $loop->the_post(); ?>
    	<?php $full_picture = get_post_meta($post->ID, 'ep_full_picture', true); ?>
    	<?php $thumb = get_post_meta($post->ID, 'ep_thumbnail_gallery', true); ?>
    	<?php $is_last = get_post_meta($post->ID, 'ep_is_fourth', true); ?>
    	<div class="one_fourth gallery-picture ">
    			<div class="gallery_frame image">
    				<a class="fancy" href="<?php echo $full_picture; ?>"><img src="<?php echo $thumb; ?>" alt=""/></a>
    <?php endwhile; ?>

    Within my custom meta box i’ve created a select tag with two option : “No” and “Yes”

    this is the code for my select meta box option

                'name' => 'Is this the fourth picture ?',
                'desc' => 'If this is the fourth picture (per row) select yes.',
                'id' => $prefix . 'is_fourth',
                'type' => 'select',
                'options' => array('No', 'Yes'),
                'std' => 'No'

    What i need is that, if the user select the “Yes” option, the yes option will echo the class “last” so, doing this the code will results :

    <div class="one_fourth gallery-picture LAST">
    			<div class="gallery_frame image">
    				<a class="fancy" href="<?php echo $full_picture; ?>"><img src="<?php echo $thumb; ?>" alt=""/></a>

    how can i achieve this ? I’ve tried a couple of thing but wasn’t working… >__<


Viewing 1 replies (of 1 total)
  • Hi Alex,

    I ran into your question while looking for a different solution. I know it’s been 4 months, and you probably came up with a solution already, but I’ll attempt to answer this question anyways.

    Based on your message, it looks like you were trying to use meta boxes to handle the forth image on your presentation layer or your theme. You could probably solve this by not using meta boxes and using a counter in your loop to catch for forth image with a PHP MOD(%). This way everything stays on your presentation layer.

    For example:

    while ( $loop->have_posts() ) : $loop->the_post();
    if ($counter % 4=0) {
    echo 'forth image: so display it how u like.';
    } else {
    echo 'not forth image...';
Viewing 1 replies (of 1 total)
  • The topic ‘Custom Post Type and class’ is closed to new replies.