WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

So I have customized a few plugins before, but never developed one from scratch. One thing that I have struggled with is structuring my functions. I found the following snippet and wonder how YOU would structure it and why?

<?php wp_reset_query(); ?>

$args = array(
'post_type'      => 'page',
'posts_per_page' => -1,
'post_parent'    => 94,
'order'          => 'DESC',
'orderby'        => 'ID',
$wp_query = new WP_Query( $args );

if ( $wp_query->have_posts() ) : ?>

<div class="row-fluid row-portfolio">

<?php $count=0; ?>    
    <?php while ( $wp_query->have_posts() ) : $wp_query->the_post(); ?>

<div class="span4">
<div class="portfolio-thumb">

        <a href="<?php the_permalink(); ?>">
    <?php echo get_the_post_thumbnail( $post_id, $attr ); ?>
    <span class="portfolio-thumb-title"><p>
            <?php the_title(); ?></p></span></a>    


<?php $count++; ?>

<?php if ($count==3 ||$wp_query->found_posts==0) :

    echo '</div><div class="row-fluid row-portfolio">';


<?php $count=0; ?>

<?php endif; ?>
<?php endwhile; ?>

<?php else : ?>                
<h3>Sorry but there are no portfolio items.</h3>
<?php endif; ?>

<?php wp_reset_query(); ?>
share|improve this question
Have you seen this? – toscho Sep 4 '13 at 20:42
It's just a query, I don't think you'd gain anything from abstracting that since it seems tied to the theme. – elclanrs Sep 4 '13 at 20:47
I don´t think it is really tied to a theme, its only dependent on the bootstrap css or am I wrong? – StenW Sep 4 '13 at 21:00

Your Answer


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

Browse other questions tagged or ask your own question.