Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

in a custom plugin I have a WPQuery, which looks like the following:

$sticky = get_option( 'sticky_posts' );
    $args = array(
        'post_type' => 'mission',
        'ignore_sticky_posts' => 1,
        'orderby' => 'date',
        'post__not_in' => $sticky,
        'posts_per_page' => $count
    );

    $latest_missions = new WP_Query( $args );
    if ( $latest_missions->have_posts() ) {
        while ( $latest_missions->have_posts() ) {
            $latest_missions->the_post();
            get_template_part( 'content-list', get_post_format() );
        }

        wp_reset_postdata();
    }

and the corresponding template part:

<li  id="post-<?php the_ID(); ?> " class="future-event"><a href="<?php the_permalink(); ?>" title="<?php printf( esc_attr__( 'Permalink to %s', 'twentyeleven' ), the_title_attribute( 'echo=0' ) ); ?>" rel="bookmark"><?php the_title(); ?></a></li>

The only problem I have is, that this will no produce semantic correct HTML, because the list is not sematically correct.

Is there a way, how I can create an <ul></ul> which is wrapped around the list, when my loop is finished?

BR, mybecks

share|improve this question
add comment

1 Answer

up vote 2 down vote accepted

Of course there is. Just do it like this:

$sticky = get_option( 'sticky_posts' );
$args = array(
    'post_type' => 'mission',
    'ignore_sticky_posts' => 1,
    'orderby' => 'date',
    'post__not_in' => $sticky,
    'posts_per_page' => $count
);

$latest_missions = new WP_Query( $args );
if ( $latest_missions->have_posts() ) {
    echo '<ul>';  // prints opening ul tag before list items
    while ( $latest_missions->have_posts() ) {
        $latest_missions->the_post();
        get_template_part( 'content-list', get_post_format() );
    }
    echo '</ul>';  // prints closing ul tag after list items

    wp_reset_postdata();
}
share|improve this answer
    
that's quite easy :) Thank you very much. –  mybecks Jul 2 '13 at 7:21
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.