Gestione del box degli eventi, correzione di alcuni bug, migliorato il readme, rinominato il file del gestore di box di pagine in modo più intuitivo

This commit is contained in:
gine 2014-11-03 01:41:28 +01:00
parent 37f0db614a
commit 2d7b17bbe5
4 changed files with 229 additions and 8 deletions

View file

@ -10,6 +10,7 @@ attrs
- ids : (Required) Serie di numeri concatenati da virgole. Gli id da prelevare.
- num = (Default 12) : (Optional) Numero di articoli da inserire nella box
- layout = 1c | 2c : (Optional) Tipo di Layout da ottenere
- box_title : (Optional) Titolo del Box
example
=======

221
ai1ec_box.php Normal file
View file

@ -0,0 +1,221 @@
<?php
function set_ai1ec_join($join, &$wp_query) {
global $wpdb;
$db_prefix=$wpdb->prefix;
$join .=" LEFT JOIN ".$db_prefix."ai1ec_events
ON $wpdb->posts.ID = ".$db_prefix."ai1ec_events.post_id";
return $join;
}
function set_ai1ec_where( $where, &$wp_query ){
global $wpdb;
if(! is_admin() && $wp_query->post_type ='ai3ec_event'){
date_default_timezone_set("Europe/Rome");
$now=time();
$where .= ' AND (' . $wpdb->ai1ec_events.start .' >= \''.$now.'\' '.
'OR ' . $wpdb->ai1ec_events.end .' >= \''.$now.'\' )';
return $where;
}
}
function set_ai1ec_limits( $limit, $query ) {
if ( ! is_admin() && $query->is_main_query() && $query->is_search() ) {
return 'LIMIT 0, 6';
}
return $limit;
}
add_filter('posts_orderby', 'set_ai1ec_orderby');
function set_ai1ec_orderby($orderby) {
$orderby = $wpdb->ai1ec_events.start." ASC";
return $orderby;
}
function get_ai1ec_box($attrs){ ?>
<?php
global $count2 ;
$box_title = "Prossimi Eventi";
if( !empty($attrs['box_title']) )
$box_title = $attrs['box_title'];
$Posts = 12;
if( !empty($attrs['num']) )
$Posts = $attrs['num'];
$home_layout = '';
if( !empty($attrs['layout']) )
$home_layout = $attrs['layout'];
$args=Array(
'post_type'=> 'ai1ec_event',
'no_found_rows' => 1,
'posts_per_page' =>$Posts,
'offset'=> '',
);
add_filter('posts_join', 'set_ai1ec_join',10,2);
add_filter( 'posts_where', 'set_ai1ec_where', 10, 2 );
add_filter('posts_orderby', 'set_ai1ec_orderby');
add_filter( 'post_limits', 'set_ai1ec_limits', 10, 2 );
$cat_query = new WP_Query($args);
remove_filter('posts_join', 'set_ai1ec_join');
remove_filter( 'posts_where', 'set_ai1ec_where');
remove_filter('posts_orderby', 'set_ai1ec_orderby');
remove_filter( 'post_limits', 'set_ai1ec_limits');
$count = 0;
?>
<?php if( $home_layout == '2c'): //************** 2C ****************************************************** ?>
<?php $count2++; ?>
<section class="cat-box column2 <?php if($count2 == 2) { echo 'last-column'; $count2=0; } ?>">
<div class="cat-box-title">
<h2><?php echo $box_title ; ?></h2>
<div class="stripe-line"></div>
</div><!-- post-thumbnail /-->
<div class="cat-box-content">
<?php if($cat_query->have_posts()): ?>
<ul>
<?php while ( $cat_query->have_posts() ) : $cat_query->the_post(); $count ++ ;?>
<?php if($count == 1) : ?>
<li <?php tie_post_class('first-news'); ?>>
<div class="inner-content">
<?php if ( function_exists("has_post_thumbnail") && has_post_thumbnail() ) : ?>
<div class="post-thumbnail">
<a href="<?php the_permalink(); ?>" title="<?php printf( esc_attr__( 'Permalink to %s', 'tie' ), the_title_attribute( 'echo=0' ) ); ?>" rel="bookmark">
<?php tie_thumb( 'tie-medium' ); ?>
<span class="overlay-icon"></span>
</a>
</div><!-- post-thumbnail /-->
<?php endif; ?>
<h2 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></h2>
<div class="entry">
<?php tie_excerpt_home() ?>
<a class="more-link" href="<?php the_permalink() ?>"><?php _e( 'Read More &raquo;', 'tie' ) ?></a>
</div>
</div>
</li><!-- .first-news -->
<?php else: ?>
<li <?php tie_post_class(); ?>>
<?php if ( function_exists("has_post_thumbnail") && has_post_thumbnail() ) : ?>
<div class="post-thumbnail">
<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>
</li>
<?php endif; ?>
<?php endwhile;?>
</ul>
<?php endif; ?>
</div><!-- .cat-box-content /-->
</section> <!-- Two Columns -->
<?php elseif( $home_layout == '1c' ): //************** 1C ****************************************************** ?>
<section class="cat-box wide-box">
<div class="cat-box-title">
<h2><?php echo $box_title ; ?></h2>
<div class="stripe-line"></div>
</div><!-- post-thumbnail /-->
<div class="cat-box-content">
<?php if($cat_query->have_posts()): ?>
<ul>
<?php while ( $cat_query->have_posts() ) : $cat_query->the_post(); $count ++ ;?>
<?php if($count == 1) : ?>
<li <?php tie_post_class( 'first-news' ); ?>>
<div class="inner-content">
<?php if ( function_exists("has_post_thumbnail") && has_post_thumbnail() ) : ?>
<div class="post-thumbnail">
<a href="<?php the_permalink(); ?>" title="<?php printf( esc_attr__( 'Permalink to %s', 'tie' ), the_title_attribute( 'echo=0' ) ); ?>" rel="bookmark">
<?php tie_thumb( 'tie-large' ); ?>
<span class="overlay-icon"></span>
</a>
</div><!-- post-thumbnail /-->
<?php endif; ?>
<h2 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></h2>
<div class="entry">
<?php tie_excerpt_home() ?>
<a class="more-link" href="<?php the_permalink() ?>"><?php _e( 'Read More &raquo;', 'tie' ) ?></a>
</div>
</div>
</li><!-- .first-news -->
<?php else: ?>
<li <?php tie_post_class(); ?>>
<?php if ( function_exists("has_post_thumbnail") && has_post_thumbnail() ) : ?>
<div class="post-thumbnail">
<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>
</li>
<?php endif; ?>
<?php endwhile;?>
</ul>
<div class="clear"></div>
<?php endif; ?>
</div><!-- .cat-box-content /-->
</section><!-- Wide Box -->
<?php else : //************** list ********************************************************************************** ?>
<section class="cat-box list-box">
<div class="cat-box-title">
<h2><?php echo $box_title ; ?></h2>
<div class="stripe-line"></div>
</div><!-- post-thumbnail /-->
<div class="cat-box-content">
<?php if($cat_query->have_posts()): ?>
<ul>
<?php while ( $cat_query->have_posts() ) : $cat_query->the_post(); $count ++ ;?>
<?php if($count == 1) : ?>
<li <?php tie_post_class( 'first-news' ); ?>>
<?php if ( function_exists("has_post_thumbnail") && has_post_thumbnail() ) : ?>
<div class="post-thumbnail">
<a href="<?php the_permalink(); ?>" title="<?php printf( esc_attr__( 'Permalink to %s', 'tie' ), the_title_attribute( 'echo=0' ) ); ?>" rel="bookmark">
<?php tie_thumb( 'tie-medium' ); ?>
<span class="overlay-icon"></span>
</a>
</div><!-- post-thumbnail /-->
<?php endif; ?>
<h2 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></h2>
<div class="entry">
<?php tie_excerpt_home() ?>
<a class="more-link" href="<?php the_permalink() ?>"><?php _e( 'Read More &raquo;', 'tie' ) ?></a>
</div>
</li><!-- .first-news -->
<?php else: ?>
<li <?php tie_post_class( 'other-news' ); ?>>
<?php if ( function_exists("has_post_thumbnail") && has_post_thumbnail() ) : ?>
<div class="post-thumbnail">
<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>
</li>
<?php endif; ?>
<?php endwhile;?>
</ul>
<div class="clear"></div>
<?php endif; ?>
</div><!-- .cat-box-content /-->
</section><!-- List Box -->
<?php endif; ?>
<?php } ?>

View file

@ -2,24 +2,23 @@
/*
Plugin Name: Sahifa Box'em'all
Plugin URI:
Description: permette tramite shortcode di ottenere dei box in stile sahifa, se usato con il plugin all-in-event-calender, anche dei box di eventi.
Description: Permette di ottenere dei box in stile sahifa per le pagine usando uno shortcode, se usato con il plugin all-in-event-calender con il medesimo modo si possono anche ottenere dei box di eventi.
Version: 0.1
Author: gin(e)
Author URI: http://ginex.indivia.net
License: BSD(3-clause) Licence
*/
require_once 'home-cats.php';
add_shortcode('sbea', 'sbea_inject_box');
//add_filter('','sbea_inject_content');
function sbea_inject_box($attrs){
if( is_home() &&
isset($attrs['type']) && isset($attrs['ids'])){
if($attrs['type']=='page'){
require_once 'page_box.php';
get_page_box($attrs);
} else if ($attrs['type']=='event') {
require_once 'ai1ec_box.php';
get_ai1ec_box($attrs);
}
}
}

View file

@ -1,6 +1,5 @@
<?php
function get_page_box($attrs){ ?>
//$post_type=ai1ec_event
<?php
global $count2 ;
$box_title = "Collettivi/Progetti";
@ -16,7 +15,7 @@ function get_page_box($attrs){ ?>
if( !empty($attrs['ids']) )
$page_ids=explode(",",$attrs['ids']);
$home_layout = '2c';
$home_layout = '';
if( !empty($attrs['layout']) )
$home_layout = $attrs['layout'];
@ -29,6 +28,7 @@ function get_page_box($attrs){ ?>
'orderby' => 'rand'
);
$cat_query = new WP_Query($args);
$count = 0;
@ -181,4 +181,4 @@ function get_page_box($attrs){ ?>
</section><!-- List Box -->
<?php endif; ?>
<?php } ?>
<?php } ?>