WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Minor Formatting Issue Can't Find Extra Space (5 posts)

  1. Walton
    Member
    Posted 3 years ago #

    Put together a query to get 2 posts per term in a particular taxonomy and then display then horizontally. (Credit where credit is due, I merged the query posts by taxonomy loop from this post with this grid format

    Works great, but the last post title is down lower than the second to last. It looks like for all the term headings, col-1 and col-2 are lined up, but for the last one, col-2 starts directly under col-1, adding an extra break.

    I can't find the issue (I'm not really a programmer just an expert cut and paster). Would really appreciate the help.

    <?php
    $terms = get_terms('skill');
    foreach ($terms as $term)
    {
    $num_cols = 2;
    $wpq = array ('taxonomy'=>'skill','term'=>$term->slug,'showposts'=>2);
    $query = new WP_Query ($wpq);
    $article_count = $query->post_count;
    echo "<h3 class=\"term-heading\" id=\"".$term->slug."\">";
    echo $term->name;
    echo "</h3>";
    if ($article_count) {
    $posts = $query->posts;
    foreach ($posts as $post) {
    for ( $i=1 ; $i <= $num_cols; $i++ ) :
    echo '<div id="col-'.$i.'" class="col">';
    $counter = $num_cols + 1 - $i;
    if( $counter%$num_cols == 0 ) :
    echo "<h2 class='entry-title'><a href=\"".get_permalink()."\">".$post->post_title."</a></h2>"
    ;?>
    <div class="entry-meta">
    <?php echo get_the_term_list( $post->ID, 'level', 'Level: ', ', ', '<br>' );
    echo get_the_term_list( $post->ID, 'skill', 'Skill: ', ', ', '<br>' );
    echo get_the_term_list( $post->ID, 'area', 'Area: ', ', ', '<br>' );
    echo get_the_term_list( $post->ID, 'theme', 'Theme: ', ', ', '<br>' );?>
    </div>
    <?php the_excerpt();
    endif; $counter++;
    rewind_posts();
    echo "</div>";
    endfor;
    wp_reset_query();
    }
    }
    }
    ?>
  2. alchymyth
    The Sweeper & Moderator
    Posted 3 years ago #

    can you post a link to your site, pointing to this particular page?

    alignment issues usually depend on css/html interaction and are nearly impossible to analyse without working on the live site (for instance using firefox web developer add-on or firebug)

  3. Walton
    Member
    Posted 3 years ago #

    Sure. It's http://www.englishadvantage.info/testblog/

    The reason that there are only 2 posts in the first two categories is that I don't have much content up yet. That's not an error with the loop (I assume!) Just trying to get everything the way I like it first.

  4. Walton
    Member
    Posted 3 years ago #

    css for that div:

    .col {
    width:47%;
    float:left;
    padding-left:2%;
    margin-bottom:17px;
    border-left: #A62800 double 3px;
    }

    Sorry thought this got posted in my reply above.

  5. Walton
    Member
    Posted 3 years ago #

    Found it. .col {margin-bottom:17px } was applying to each individual post, not the two post grid. Took that away and it works fine.

    Anyone who wants to pull posts from a custom taxonomy listed by value and/or display them in a grid format, I highly recommend the two articles I linked to above. Works great.

Topic Closed

This topic has been closed to new replies.

About this Topic