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

I tried incrementally adding in my widget area to the masonry layout (PHP below) it appears but I cannot get it included into the masonry like the other blocks.

        $counts = 0 ;
        $addin = get_sidebar('masonry'); 

        foreach ($posts as $post) : setup_postdata($post); $counts++; ?>
                <div class="box">
                <?php  if($count == 9) {echo $addin;} else {?>
                <a href="<?php the_permalink() ?>">
                <h2><?php the_title(); echo $counts; // just to see ?></h2>
                <?php if (has_post_thumbnail()) {
                <?php the_content();?></a>
                </div><?php } endforeach; ?>

I also tried this jQuery but it broke my masonry:

       itemSelector: '.box',
       isFitWidth: true,
        var $container = $('#mas-widget');
        var addinWidget = $('<div class="element"><?php get_sidebar('masonry');?></div>');

Could someone lead me in the right direction to place my widgets correctly inside the masonry layout AT/NEXT TO or IN FRONT OF a specified block number?

share|improve this question
Anybody have any advice at all? – BenRacicot Jan 31 '13 at 3:26
up vote 1 down vote accepted

Figured it out! Here's the get_posts method to add a widget (or any content into a masonry layout at the "$counts" number you define)

<div class="arrange">
        $args = array(
            'posts_per_page'  => 10000,
            'offset'          => 5,
            'orderby'         => 'post_date',
            'order'           => 'DESC',
            'exclude'         => 'none',
            // 'post_type'       => array('post', 'page', 'video_type', 'review_type' ),
            'post_status'     => 'publish',
            'suppress_filters' => true 

        $posts = get_posts($args);
        $counts = 0 ;
        foreach ($posts as $post) : setup_postdata($post); $counts++; 
                <div class="box"> 
                    <a href="<?php the_permalink() ?>">
                        <h2><?php the_title(); echo $counts; // to see your box number ?></h2>
                        <?php if (has_post_thumbnail()) {the_post_thumbnail('masonry');} 
                </div><?php if($counts == 9) { get_sidebar('masonry');}
                endforeach; ?>

    </div> <!-- end masonry -->
share|improve this answer

Your Answer


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.