• Resolved adayin

    (@adayin)


    Hi there, I am trying to get a website to display 9 posts from a specific category in three columns on an archive/category page.

    I’m also using this snippet of code to call a CSS class when the the 3rd column has a post:

    <? if ( $postcount%3 == 0 ) { echo ' last'; } ?>

    Obviously I need to include a postcount in the loop to get this to work and at the moment the code above does not know when to call the .last style.

    Please could some one give me a hand with this.

    Thank you very much.

    P.S. This is the code from the page I’m working on:

    <?php get_header(); ?>
    
    <div id="work_wrap">
    
    <h2 class="headers">Recent work </h2>
    
    <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
    
    <div id="work">	   			
    
    <div class="work_item<? if ( $postcount%3 == 0 ) { echo ' last'; } ?>">
    <a href="<?php the_permalink() ?>" rel="bookmark" title="<?php the_title(); ?>"><?php echo get_post_image (get_the_id(), '', '', '' .get_bloginfo('template_url') .'/scripts/timthumb.php?zc=1&w=300&h=177&src='); ?></a>
    <p><?php foreach((get_the_category()) as $category) { echo $category->cat_name . ''; } ?>: <a href="<?php the_permalink() ?>" rel="bookmark" title="<?php the_title_attribute(); ?>"><?php the_title(); ?></a></p>
    </div><!--END WORK ITEM CLASS-->
    
    </div>
    
    <?php endwhile; ?>
    
    <?php include (TEMPLATEPATH . '/pagination.php'); ?>
    
    <?php else : ?>
    
    <p><?php _e('Sorry, no posts matched your criteria.'); ?></p>
    <?php endif; ?>
    
    </div><!--END WORK_WRAP WRAPPER-->
    
    <?php get_sidebar(); ?>
    <?php get_footer(); ?>
Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter adayin

    (@adayin)

    Oh I also forgot to mention that there will be 9 posts per page and showing the children of one specific category. ??

    Thread Starter adayin

    (@adayin)

    I managed to get this working in the end. Just for those that may want to know, this is how:

    <?php get_header(); ?>
    
    <div id="work_wrap">
    
    <h2 class="headers">Recent work </h2>
    
    		<?php $postcount = 0; ?>
    
    		<?php if ( have_posts() ) : while(have_posts()) : the_post();  ?>
    
    			<?php $postcount++; ?>
    
    <div id="work">
    
    <div class="work_item<? if ( $postcount%3 == 0 ) { echo ' last'; } ?>">
    <a href="<?php the_permalink() ?>" rel="bookmark" title="<?php the_title(); ?>"><?php echo get_post_image (get_the_id(), '', '', '' .get_bloginfo('template_url') .'/scripts/timthumb.php?zc=1&w=300&h=177&src='); ?></a>
    <p><?php foreach((get_the_category()) as $category) { echo $category->cat_name . ''; } ?>: <a href="<?php the_permalink() ?>" rel="bookmark" title="<?php the_title_attribute(); ?>"><?php the_title(); ?></a></p>
    </div><!--END WORK ITEM CLASS-->
    </div>
    
    <?php endwhile; ?>
    
    	<?php include (TEMPLATEPATH . '/pagination.php'); ?>
    
    	<?php else : ?>
    
    <p><?php _e('Sorry, no posts matched your criteria.'); ?></p>
    <?php endif; ?>
    
    </div><!--END WORK_WRAP WRAPPER-->
    
    <?php get_sidebar(); ?>
    <?php get_footer(); ?>
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘$postcount help needed.’ is closed to new replies.