WordPress.org

Ready to get started?Download WordPress

Forums

insight on $post_num (2 posts)

  1. gmisen
    Member
    Posted 5 years ago #

    i'm having trouble finding information on $post_num

    what it is and what it does and what you can do with it.

    I'm using it like this:

    <?php $my_query = new WP_Query('category_name=localexperts&posts_per_page=-1&meta_key=le_region&meta_value=Asia'); ?>
    
    <table class="le_table">
    
    <?php while ($my_query->have_posts()) : $my_query->the_post(); update_post_caches($posts); ?>
    
    <?php wp_link_pages(array('before' => '<p><strong>Pages:</strong> ', 'after' => '</p>', 'next_or_number' => 'number')); ?>
    
    <?php if ( ++$post_num % 2 ) { ?>
    
    <tr>
    <td class="le_tableleft">
    <div class="localexp"><?php echo gi_thumb(1); ?>
    <span class="posttitle"><?php the_title(); ?></span><?php the_excerpt(); ?><br class="clear" /><?php the_content(); ?>
    </div>
    </td>
    
    <?php } else { ?>
    
    <td class="le_tableright">
    <div class="localexp"><?php echo gi_thumb(1); ?>
    <span class="posttitle"><?php the_title(); ?></span><?php the_excerpt(); ?><br class="clear" /><?php the_content(); ?>
    </div>
    </td>
    </tr>
    
    <?php } ?>

    Building a table dynamically, every two posts creating a table row (so that they will be the same height, the longest entry setting the height)

    problem is, i have multiple loops on this page all doing that

    i need the post_num to "reset" at each loop

    if it ends on an odd post, the first post in the next loop should be odd as well ('1'), but now thats not the case

    anyone use $post_num much?

  2. gmisen
    Member
    Posted 5 years ago #

    Wow, by chance I just happened upon a waaay more elegant method of doing what I was trying to do right here:

    http://wordpressgarage.com/code-snippets/publishing-wordpress-posts-in-two-columns/

    I've seen something like this before, but the key was to add a "clear:both;" div after every two. nice!

    But still, if anyone has any insight into what exactly $post_num is or does, I'd be interested in hearing!

    thanks

Topic Closed

This topic has been closed to new replies.

About this Topic