• Resolved arcab4

    (@arcab4)


    Issue: i am trying to display all the posts that belong in a certain category. I’ve figured out how to do that but it shows the results in one long column. What i’d like to do is determine the # of columns to show the results in (in this case 3 columns) and then the posts would be automatically sorted and listed.

    so visually it would be great like this…

    post a post e post i
    post b post f post j
    post c post g post k
    post d post h post l

    The coding I came up with is:

    <?php query_posts('cat=46&orderby=title&order=asc'); ?>
    <table border="1">
    <tr>
    <td valign="top">
    <?php
    $iTotalPosts = 0;
    while (have_posts()) : the_post();
    $iTotalPosts++;
    endwhile;
    
    $iPostCounter = 1;
    $iNumberofColumns= 3;
    $iPostsPerColumns = ceil($iTotalPosts/$iNumberofColumns);
    
    if( $iPostsPerColumns == 0 ){
        $iPostsPerColumns = $iTotalPosts;
    }
    
    while (have_posts()) : the_post();
    if (($iPostCounter % iPostsPerColumns) == 0){
    echo('</td><td valign="top">');
    }
    ?>
    <span class="listings"><a href=" <?php the_permalink(); ?>" title="Permanent
    link to <?php the_title(); ?>"><?php the_title('','','>'); ?></a></span>
    <?php
    $iPostCounter++;
    endwhile;
    ?>
    
    </td>
    </tr>
    </table>

    it’s not quite there yet as i get an error message of

    Warning: Division by zero

    the line that causes the error i believe is:

    $iPostsPerColumns = ceil($iTotalPosts/$iNumberofColumns);

    If it’s division by zero error, that means the $iNumbersofColumns must not be passing correctly?

  • The topic ‘Trouble with Organizing Post Results’ is closed to new replies.