* @copyright Copyright (c) 2013, Nicolas GUILLAUME * @link http://themesandco.com/customizr * @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html */ if ( ! class_exists( 'TC_post_list' ) ) : class TC_post_list { static $instance; function __construct () { self::$instance =& $this; //displays the article with filtered layout : content + thumbnail add_action ( '__loop' , array( $this , 'tc_post_list_display')); //Include attachments in search results add_filter ( 'pre_get_posts' , array( $this , 'tc_include_attachments_in_search' )); //Include all post types in archive pages add_filter ( 'pre_get_posts' , array( $this , 'tc_include_cpt_in_lists' )); } /** * Includes Custom Posts Types (set to public and excluded_from_search_result = false) in archives and search results * In archives, it handles the case where a CPT has been registered and associated with an existing built-in taxonomy like category or post_tag * * @package Customizr * @since Customizr 3.1.20 */ function tc_include_cpt_in_lists($query) { if ( is_admin() || ! $query->is_main_query() || ! apply_filters('tc_include_cpt_in_archives' , false) || ! ( $query->is_search || $query->is_archive ) ) return; //filter the post types to include, they must be public and not excluded from search $post_types = get_post_types( array( 'public' => true, 'exclude_from_search' => false) ); $query->set('post_type', $post_types ); } /** * The default template for displaying posts lists. * * @package Customizr * @since Customizr 3.0.10 */ function tc_post_list_display() { global $wp_query; //must be archive or search result. Returns false if home is empty in options. if ( is_singular() || is_404() || (is_search() && 0 == $wp_query -> post_count) || tc__f( '__is_home_empty') ) return; //When do we show the post excerpt? //1) when set in options //2) + other filters conditions $tc_show_post_list_excerpt = ( 'full' == esc_attr( tc__f( '__get_option' , 'tc_post_list_length' )) ) ? false : true; $tc_show_post_list_excerpt = apply_filters( 'tc_show_post_list_excerpt', $tc_show_post_list_excerpt ); //we get the thumbnail data (src, width, height) if any $thumb_data = $this -> tc_get_post_list_thumbnail(); //gets the filtered post list layout $layout = apply_filters( 'tc_post_list_layout', TC_init::$instance -> post_list_layout ); //when do we display the thumbnail ? //1) there must be a thumbnail //2) the excerpt option is not set to full //3) filter's conditions $tc_show_post_list_thumb = $tc_show_post_list_excerpt ? true : false; $tc_show_post_list_thumb = empty($thumb_data[0]) ? false : $tc_show_post_list_thumb; $tc_show_post_list_thumb = apply_filters( 'tc_show_post_list_thumb', $tc_show_post_list_thumb ); //what is determining the layout ? if no thumbnail then full width + filter's conditions $post_list_content_class = $tc_show_post_list_thumb ? $layout['content'] : 'span12'; $post_list_content_class = apply_filters( 'tc_post_list_content_class', $post_list_content_class , $tc_show_post_list_thumb ); //Renders the filtered layout for content + thumbnail if ( isset($layout['alternate']) && $layout['alternate'] ) { if ( 0 == $wp_query->current_post % 2 ) { $this -> tc_post_list_content($post_list_content_class, $tc_show_post_list_excerpt); $tc_show_post_list_thumb ? $this -> tc_post_list_thumbnail( $thumb_data , $layout['thumb'] ) : false; } else { $tc_show_post_list_thumb ? $this -> tc_post_list_thumbnail( $thumb_data , $layout['thumb'] ) : false; $this -> tc_post_list_content($post_list_content_class, $tc_show_post_list_excerpt); } } else if ( isset($layout['show_thumb_first']) && !$layout['show_thumb_first'] ) { $this -> tc_post_list_content($post_list_content_class, $tc_show_post_list_excerpt); $tc_show_post_list_thumb ? $this -> tc_post_list_thumbnail( $thumb_data , $layout['thumb'] ) : false; } else { $tc_show_post_list_thumb ? $this -> tc_post_list_thumbnail( $thumb_data , $layout['thumb'] ) : false; $this -> tc_post_list_content($post_list_content_class, $tc_show_post_list_excerpt); } //renders the hr separator after each article echo apply_filters( 'tc_post_list_separator', '