Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*dynamically added row break*/
- <?php $portfolio_count = $the_query->current-post + 1; ?>
- <?php if($portfolio_count % 4 = 0) : ?>
- </div><div class="row">
- <?php endif; ?>
- /*another*/
- <?php $q = new WP_Query( array( 'posts_per_page' => 6 ) ); // Edit your query ?>
- <?php if( $q->have_posts() ) : ?>
- <?php while ( $q->have_posts() ) : $q->the_post(); ?>
- <?php if( 0 === ( $q->current_post ) % 3 ): ?>
- <!--Begin Row:--> <div class="row" data-equalizer>
- <?php endif; ?>
- <!--Item: -->
- <div class="large-4 medium-4 columns" data-equalizer-watch>
- <?php get_template_part( 'partials/loop', 'archive-grid' ); ?>
- </div>
- <?php if( 0 === ( $q->current_post + 1 ) % 3 || ( $q->current_post + 1 ) === $q->post_count ): ?>
- <!--End Row: --> </div>
- <?php endif; ?>
- <?php endwhile; ?>
- <?php wp_reset_postdata(); ?>
- <?php else : ?>
- <?php get_template_part( 'partials/content', 'missing' ); ?>
- <?php endif; ?>
- This should give you the following layouts with three items per row:
- #posts: 1
- <div class="row" data-equalizer>
- <div class="large-4 medium-4 columns" data-equalizer-watch>
- <--Content Stuff-->
- </div>
- </div>
- #posts: 2
- <div class="row" data-equalizer>
- <div class="large-4 medium-4 columns" data-equalizer-watch>
- <--Content Stuff-->
- </div>
- <div class="large-4 medium-4 columns" data-equalizer-watch>
- <--Content Stuff-->
- </div>
- </div>
- #posts: 3
- <div class="row" data-equalizer>
- <div class="large-4 medium-4 columns" data-equalizer-watch>
- <--Content Stuff-->
- </div>
- <div class="large-4 medium-4 columns" data-equalizer-watch>
- <--Content Stuff-->
- </div>
- <div class="large-4 medium-4 columns" data-equalizer-watch>
- <--Content Stuff-->
- </div>
- </div>
- You can use the following built-in properties of the WP_Query() class:
- WP_Query::current_post // Index of the current post, starts at 0
- WP_Query::found_posts // The total number of posts found
- WP_Query::post_count // The number of posts being displayed.
- to make your life eaiser, instead of introducing custom counters.
- Here's an example that works on my install:
- <?php $q = new WP_Query( array( 'posts_per_page' => 6 ) ); // Edit your query ?>
- <?php if( $q->have_posts() ) : ?>
- <?php while ( $q->have_posts() ) : $q->the_post(); ?>
- <?php if( 0 === ( $q->current_post ) % 3 ): ?>
- <!--Begin Row:--> <div class="row" data-equalizer>
- <?php endif; ?>
- <!--Item: -->
- <div class="large-4 medium-4 columns" data-equalizer-watch>
- <?php get_template_part( 'partials/loop', 'archive-grid' ); ?>
- </div>
- <?php if( 0 === ( $q->current_post + 1 ) % 3 || ( $q->current_post + 1 ) === $q->post_count ): ?>
- <!--End Row: --> </div>
- <?php endif; ?>
- <?php endwhile; ?>
- <?php wp_reset_postdata(); ?>
- <?php else : ?>
- <?php get_template_part( 'partials/content', 'missing' ); ?>
- <?php endif; ?>
- This should give you the following layouts with three items per row:
- #posts: 1
- <div class="row" data-equalizer>
- <div class="large-4 medium-4 columns" data-equalizer-watch>
- <--Content Stuff-->
- </div>
- </div>
- #posts: 2
- <div class="row" data-equalizer>
- <div class="large-4 medium-4 columns" data-equalizer-watch>
- <--Content Stuff-->
- </div>
- <div class="large-4 medium-4 columns" data-equalizer-watch>
- <--Content Stuff-->
- </div>
- </div>
- #posts: 3
- <div class="row" data-equalizer>
- <div class="large-4 medium-4 columns" data-equalizer-watch>
- <--Content Stuff-->
- </div>
- <div class="large-4 medium-4 columns" data-equalizer-watch>
- <--Content Stuff-->
- </div>
- <div class="large-4 medium-4 columns" data-equalizer-watch>
- <--Content Stuff-->
- </div>
- </div>
- and
- #posts: 4
- <div class="row" data-equalizer>
- <div class="large-4 medium-4 columns" data-equalizer-watch>
- <--Content Stuff-->
- </div>
- <div class="large-4 medium-4 columns" data-equalizer-watch>
- <--Content Stuff-->
- </div>
- <div class="large-4 medium-4 columns" data-equalizer-watch>
- <--Content Stuff-->
- </div>
- </div>
- <div class="row" data-equalizer>
- <div class="large-4 medium-4 columns" data-equalizer-watch>
- <--Content Stuff-->
- </div>
- </div>
- /*another*/
- <?php /* Template Name: Page TOP movies */ get_header(); ?>
- <div class="container">
- <div class="row">
- <div class="col-lg-12">
- <div class="page-header">
- <h1 id="type">TOP filmai</h1>
- </div>
- </div>
- </div>
- <?php
- //Set the counter to 1
- $i = 1;
- //Open the row div
- echo '<div class="row"><div class="movie_list">'; ?>
- <?php $custom_query = new WP_Query( array( 'posts_per_page' => 24, 'meta_key' => 'wpb_post_views_count', 'orderby' => 'meta_value_num', 'order' => 'DESC' ) );
- while($custom_query->have_posts()) : $custom_query->the_post(); ?>
- <div class="col-md-2">
- <div class="well">
- <h6><a href="<?php the_permalink();?>"><?php if (strlen($post->post_title) > 35) {
- echo substr(the_title($before = '', $after = '', FALSE), 0, 25) . '...'; } else {
- the_title();
- } ?></a></h6>
- <a href="<?php the_permalink();?>"><?php the_post_thumbnail('movie-thumb', array('class' => 'img-thumbnail')); ?></a>
- <a href="<?php the_permalink();?>"><button type="button" class="btn btn-default btn-sm btn-block"><span class="glyphicon glyphicon-play"></span> Žiūrėti</button></a>
- </div>
- </div>
- <?php $i++; if($i % 6 == 0) {echo '</div></div><div class="row"><div class="movie_list">'; ?>
- <?php } ?>
- <?php endwhile; ?>
- </div></div>
- <?php wp_reset_postdata(); // reset the query ?>
- <?php get_footer(); ?>
- /*another*/
- <div class="row">
- <?php
- $args = array('post_type' => 'portfolio');
- $the_query = new WP_Query($args);
- ?>
- <?php if(have_posts()) : while( $the_query->have_posts()) : $the_query->the_post(); ?>
- <div class="col-sm-3 portfolio-piece">
- <?php
- $thumbnail_id = get_post_thumbnail_id();
- $thumbnail_url = wp_get_attachment_image_src( $thumbnail_id, 'thumbnail-size', true);
- ?>
- <img src="<?php echo $thumbnail_url[0]; ?>" alt="<?php the_title(); ?>" />
- <h3><?php the_title(); ?></h3>
- </div>
- <!--dynamic row break code after 4 post-->
- <?php $portfolio_count = $the_query->current-post + 1; ?>
- <?php if($portfolio_count % 4 = 0) : ?>
- </div><div class="row">
- <!--every 4 posts close div and open new div with class </row>-->
- <?php endif; ?>
- <?php endwhile; endif; ?>
- </div>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement