/** * nice_masonry_blog_ajax() * * Ajax function for the masonry blog * * @since 1.0.0 * */ function nice_masonry_blog_ajax($args = array()) { check_ajax_referer('play-nice', 'nonce'); if (!empty($_POST)) { $page = isset($_POST['pageNumber']) ? $_POST['pageNumber'] : 0; $output = ''; $columns = 3; $loop = 0; $query_args = array('posts_per_page' => get_option('posts_per_page'), 'paged' => $page); // The Query $query = new WP_Query($query_args); // The Loop if ($query->have_posts()) { while ($query->have_posts()) { $query->the_post(); $loop++; $class = ''; if ($loop % $columns == 0) { $class = 'last'; } if (($loop - 1) % $columns == 0) { $class = 'first'; } $output .= '<div id="post-' . get_the_ID() . '" class="masonry-item isotope-item columns-' . $columns . ' ' . $class . '">'; $output .= '<!-- BEGIN .post -->'; $output .= '<article class="post clearfix">'; if (has_post_thumbnail()) { $output .= '<figure class="featured-image view view-more">'; $output .= '<a href="' . get_permalink() . '" title="' . sprintf(__('Permanent Link to %s', 'nicethemes'), get_the_title()) . '">'; $output .= nice_image(array('width' => 580, 'height' => 405, 'class' => 'wp-post-image', 'echo' => false)); $output .= '</a>'; $output .= '</figure>'; } $output .= '<header>'; $output .= '<h2 class="post-title">'; $output .= '<a href="' . get_permalink() . '" rel="bookmark" title="' . sprintf(__('Permanent Link to %s', 'nicethemes'), get_the_title()) . '">' . get_the_title() . '</a>'; $output .= '</h2>'; ob_start(); nice_post_meta_masonry(); $post_meta_masonry = ob_get_contents(); ob_end_clean(); $output .= $post_meta_masonry; $output .= '</header>'; $output .= '<div class="entry">'; $output .= '<div class="post-content">'; $nice_excerpt = substr(get_the_excerpt(), 0, 400); //truncate excerpt according to $len if (strlen($nice_excerpt) < strlen(get_the_excerpt())) { $nice_excerpt = $nice_excerpt . "..."; } $output .= '<p>' . $nice_excerpt . '</p>'; $output .= '<a class="readmore" href="' . get_permalink() . '" title="' . sprintf(__('Permanent Link to %s', 'nicethemes'), get_the_title()) . '">' . __('Read More', 'nicethemes') . '</a>'; $output .= '</div>'; $output .= '</div>'; $output .= '<!-- END .post -->'; $output .= '</article>'; $output .= '</div>'; } } else { $output .= '<div class="no-more-posts clearfix"><span>' . __('No More Posts Found.', 'nicethemes') . '</span></div>'; } echo $output; /* Restore original Post Data */ wp_reset_postdata(); } die; }
<!-- BEGIN .post --> <article class="post clearfix"> <?php if ( has_post_thumbnail() ) : ?> <figure class="featured-image view view-more"> <a href="<?php the_permalink(); ?>" title="<?php printf( __( 'Permanent Link to %s', 'nicethemes' ), get_the_title() ); ?>"> <?php nice_image( array( 'width' => 580, 'height' => 405, 'class' => 'wp-post-image' ) ); ?> </a> </figure> <?php endif; ?> <header> <h2 class="post-title"> <a href="<?php the_permalink() ?>" rel="bookmark" title="<?php printf( __( 'Permanent Link to %s', 'nicethemes' ), get_the_title() ); ?>"><?php the_title(); ?></a> </h2> <?php nice_post_meta_masonry(); ?> </header> <div class="entry"> <div class="post-content"> <?php the_excerpt(); ?> <a class="readmore" href="<?php echo get_permalink( get_the_ID() ); ?>" title="<?php printf( __( 'Permanent Link to %s', 'nicethemes' ), get_the_title() ); ?>"> <?php _e( 'Read More', 'nicethemes' ); ?></a> </div> </div> <!-- END .post --> </article>