Browse Source

Aggiunta la paginazione, migliorata la gestione degli argomenti, modificata la documentazione di conseguenza

gine 9 years ago
parent
commit
72123569a9
3 changed files with 41 additions and 18 deletions
  1. 5 2
      README.md
  2. 12 4
      ai1ec_box.php
  3. 24 12
      page_box.php

+ 5 - 2
README.md

@@ -8,13 +8,16 @@ attrs
 
 - type = page | event : (Required) Tipo di post
 - ids : (Required) Serie di numeri concatenati da virgole. Gli id da prelevare.
-- num = (Default 12) : (Optional) Numero di articoli da inserire nella box
+- num : (Optional) Numero di articoli da inserire nella box. Default 12
 - layout = 1c | 2c : (Optional) Tipo di Layout da ottenere
-- box_title : (Optional) Titolo del Box
+- title : (Optional) Titolo del Box. 
+- offset : (Optional) Numero di post da saltare prima di incominciare con la pubblicazione.
+- paged = y | n : (Optional) paginazione per il box. Default 'n'. Disponibile solo per type=page
 
 example
 =======
 
 - [sbea type="page" ids="11,22"]
 - [sbea type="page" ids="11,22" layout="1c" num="4"]
+- [sbea type="event" ids="34" layout="1c" num="5" title="Prossimi Eventi"]
 

+ 12 - 4
ai1ec_box.php

@@ -39,8 +39,8 @@ function get_ai1ec_box($attrs){ ?>
 <?php
 	global $count2 ;
 	$box_title = "Prossimi Eventi";
-	if( !empty($attrs['box_title']) )
-		$box_title = $attrs['box_title'];
+	if( !empty($attrs['title']) )
+		$box_title = $attrs['title'];
 
 	$Posts = 12;
 	if( !empty($attrs['num']) )
@@ -50,15 +50,23 @@ function get_ai1ec_box($attrs){ ?>
 	if( !empty($attrs['layout']) )
 		$home_layout = $attrs['layout'];
 	
+	$offset = '';
+	if( !empty($attrs['offset']) )
+		$home_layout = $attrs['offset'];
+	
+	$page_ids=Array();
+ 	if( !empty($attrs['ids']) )
+ 		$page_ids=explode(",",$attrs['ids']);
+
 	$args=Array(
 		'post_type'=> 'ai1ec_event',
 		'no_found_rows' => 1,
-		'posts_per_page' =>$Posts,
+		'posts_per_page' => $Posts,
 		'offset'=> '',
 		'tax_query' => array(
 			array(
 				'field'     => 'id',
-				'terms'  => array(34),
+				'terms'  => $page_ids,
 				'taxonomy' => 'events_categories',
 			)
 		),

+ 24 - 12
page_box.php

@@ -1,16 +1,14 @@
 <?php 
-function get_page_box($attrs){ ?>
-<?php
+function get_page_box($attrs){
 	global $count2 ;
 	$box_title = "Collettivi/Progetti";
-	if( !empty($attrs['box_title']) )
-		$box_title = $attrs['box_title'];
+	if( !empty($attrs['title']) )
+		$box_title = $attrs['title'];
 
 	$Posts = 12;
 	if( !empty($attrs['num']) )
 		$Posts = $attrs['num'];
 	
-	//$page_ids_arr=Array('80','71','16');
 	$page_ids=Array();
 	if( !empty($attrs['ids']) )
 		$page_ids=explode(",",$attrs['ids']);
@@ -19,20 +17,26 @@ function get_page_box($attrs){ ?>
 	if( !empty($attrs['layout']) )
 		$home_layout = $attrs['layout'];
 	
+	$offset = '';
+	if( !empty($attrs['offset']) )
+		$home_layout = $attrs['offset'];
+	
 	$args=Array(
 		'post_type'=> 'page',
 		'post__in' => $page_ids,
-		'no_found_rows' => 1,
-		'posts_per_page' =>$Posts,
-		'offset'=> '',
+		'posts_per_page' => $Posts,
+		'offset'=> $offset,
 		'orderby' => 'rand'
 	);
 	
+	$attrs['paged'] = 'y';
+	if ( !empty( $attrs['paged'] ) && $attrs['paged'] == 'y' )
+		$args[ 'paged' ] = get_query_var('paged');
+	else $args[ 'no_found_rows' ] = 1 ;
 	
 	$cat_query = new WP_Query($args);
 
 	$count = 0;
-
 ?>
 	<?php if( $home_layout == '2c'):  //************** 2C ****************************************************** ?>
 		<?php $count2++; ?>
@@ -40,7 +44,8 @@ function get_page_box($attrs){ ?>
 			<div class="cat-box-title">
 				<h2><?php echo $box_title ; ?></h2>
 				<div class="stripe-line"></div>
-			</div><!-- post-thumbnail /-->
+			</div>
+			<!-- post-thumbnail /-->
 			<div class="cat-box-content">
 			
 				<?php if($cat_query->have_posts()): ?>
@@ -73,7 +78,9 @@ function get_page_box($attrs){ ?>
 								<a href="<?php the_permalink(); ?>" title="<?php printf( esc_attr__( 'Permalink to %s', 'tie' ), the_title_attribute( 'echo=0' ) ); ?>" rel="bookmark"><?php tie_thumb(); ?><span class="overlay-icon"></span></a>
 							</div><!-- post-thumbnail /-->
 						<?php endif; ?>			
-						<h3 class="post-box-title"><a href="<?php the_permalink(); ?>" title="<?php printf( esc_attr__( 'Permalink to %s', 'tie' ), the_title_attribute( 'echo=0' ) ); ?>" rel="bookmark"><?php the_title(); ?></a></h3>
+						<h3 class="post-box-title">
+							<a href="<?php the_permalink(); ?>" title="<?php printf( esc_attr__( 'Permalink to %s', 'tie' ), the_title_attribute( 'echo=0' ) ); ?>" rel="bookmark"><?php the_title(); ?></a>
+						</h3>
 						<div class="entry">
 							<?php tie_excerpt_home() ?>
 						</div>
@@ -81,7 +88,7 @@ function get_page_box($attrs){ ?>
 					<?php endif; ?>
 				<?php endwhile;?>
 				</ul>
-
+				<div class="clear"></div>
 				<?php endif; ?>
 			</div><!-- .cat-box-content /-->
 		</section> <!-- Two Columns -->
@@ -190,4 +197,9 @@ function get_page_box($attrs){ ?>
 		</section><!-- List Box -->
 
 	<?php endif; ?>
+	<?php if ( !empty($attrs['paged'] ) && $attrs['paged'] == 'y' 
+				&& empty($offset) &&  $cat_query->max_num_pages > 1){?> 
+		<div class="recent-box-pagination"><?php tie_pagenavi($cat_query , $Posts); ?> </div> 
+	<?php } ?>
+	<div class="clear"></div>
 <?php } ?>