- <?php
- class front_page{
- static $adds = true;
- static function get_categories( $nr = -1 ){
- $categories = get_categories();
- $result = array();
- foreach($categories as $key => $category){
- if( $key == $nr ){
- break;
- }
- if( $nr > 0 ){
- $result[ $category -> term_id ] = $category -> term_id;
- }else{
- $result[ $category -> term_id ] = $category -> cat_name;
- }
- }
- return $result;
- }
- static function get_pages(){
- $pages = get_pages();
- $result = array();
- foreach($pages as $page){
- $result[ $page -> ID ] = $page -> post_title;
- }
- return $result;
- }
- static function get_front_page_content( ){
- $result = '';
- switch( admin_options::get_values('front_page' , 'resources') ){
- case 'categories' :{
- $result = self::get_content_categories();
- if( empty( $result ) ){
- $result = self::get_null_content();
- }
- break;
- }
- case 'page' :{
- $result = self::get_content_page();
- break;
- }
- case 'selected_posts' : {
- $result = self::get_content_selected_posts( );
- $result .= self::get_content_latest_posts( );
- break;
- }
- default :{
- $result = self::get_content_latest_posts( );
- break;
- }
- }
- return $result;
- }
- static function get_front_page_layout( ){
- $result = '<div class="breadcrumbs">';
- $result .= '<p>'.__('You are here:','cosmotheme').'</p>';
- $result .= '<ul>';
- $result .= '<li>';
- $result .= '<a href="'.home_url().'">' . __('Home' , 'cosmotheme') . '</a>';
- $result .= '</li>';
- $result .= '</ul>';
- $result .= '</div>';
- if( strlen( admin_options::get_values('advertising','zone_1' ) ) ){
- $result .= '<div class="cosmo-ads">';
- $result .= admin_options::get_values('advertising','zone_1' );
- $result .= '</div>';
- }
- switch( admin_options::get_values('front_page' , 'layout') ){
- case 'full-width' :{
- $result .= '<div class="b w_940 b_page_c" id="content">';
- $result .= self::get_front_page_content();
- $result .= '</div>';
- break;
- }
- case 'right-sidebar' :{
- $result .= '<div class="b w_620 b_page_c" id="content">';
- $result .= self::get_front_page_content();
- $result .= '</div>';
- $result .= '<div class="b w_300 full b_right_area widget-area b_right_area" id="primary" role="complementary">';
- ob_start();
- ob_clean();
- de_load_sidebar( );
- $result .= ob_get_clean();
- $result .= '</div>';
- break;
- }
- case 'left-sidebar' :{
- $result .= '<div class="b w_300 full b_right_area widget-area b_right_area" id="primary" role="complementary">';
- ob_start();
- ob_clean();
- de_load_sidebar( );
- $result .= ob_get_clean();
- $result .= '</div>';
- $result .= '<div class="b w_620" id="content">';
- $result .= self::get_front_page_content();
- $result .= '</div>';
- break;
- }
- }
- echo $result;
- }
- static function get_content_categories( ){
- $categories = admin_options::get_values( 'front_page' , 'categories' );
- $result = '';
- $i = 1;
- if( !empty( $categories ) ){
- foreach( $categories as $id){
- $cat = get_category( $id );
- if( admin_options::get_values( 'front_page' , 'layout' ) == 'full-width'){
- $nr = 3;
- }else{
- $nr = 2;
- }
- if( $i % $nr == 0 ){
- $i = 1;
- $classes = 'last';
- }else{
- $i++;
- $classes = '';
- }
- $posts = query_posts('cat='.$id.'&posts_per_page='.admin_options::get_values( 'front_page' , 'nr_post_cat' ) );
- $j = 1;
- $result .= '<div class="b w_300 cosmo-category '.$classes.'">';
- foreach( $posts as $index => $post ){
- if( $j == 1 ){
- $result .= '<h3 class="title"><a href="' . get_category_link( $cat -> term_id ) . '" title="' . __('Permalink to','cosmotheme') . ' ' . $cat -> cat_name . '">' . $cat -> cat_name . '</a></h3>';
- $result .= '<div class="cosmo-category-content cosmo-swap fade">';
- /*if( has_post_thumbnail( $post -> ID ) ){
- $result .= '<a href="' . get_permalink( $post -> ID ) . '" rel="bookmark" class="cosmo-image">';
- $args = array(
- 'numberposts' => -1,
- 'post_type' => 'attachment',
- 'status' => 'publish',
- 'post_mime_type' => 'image',
- 'post_parent' => $post -> ID
- );
- $images = &get_children($args);
- if( isset( $images[ get_post_thumbnail_id( $post -> ID ) ] ) ){
- $text = $images[ get_post_thumbnail_id( $post -> ID ) ] -> post_excerpt;
- }else{
- $args = array(
- 'numberposts' => -1,
- 'post_type' => 'attachment',
- 'status' => 'publish',
- 'post_mime_type' => 'image',
- 'post_parent' => 0
- );
- $images = &get_children($args);
- if( isset( $images[ get_post_thumbnail_id( $post -> ID ) ] ) ){
- $text = $images[ get_post_thumbnail_id( $post -> ID ) ] -> post_excerpt;
- }else{
- $text = '';
- }
- }*/
- $text = ''; $result .= '<a href="' . get_permalink( $post -> ID ) . '" rel="bookmark" class="cosmo-image">';
- $result .= '<span class="mosaic-overlay details">' . $text . '</span>';
- $result .= '<span style="background: url('.get_template_directory_uri().'/images/categories/'.$cat -> term_id.'.jpg)"></span>';
- $result .= '</a>';
- /*}else{
- $result .= '<a href="' . get_permalink( $post -> ID ) . '" rel="bookmark" class="cosmo-image no-image">';
- $result .= '<span></span>';
- $result .= '</a>';
- }*/
- if('open' == $post->comment_status)
- {
- $result .= '<p class="cosmo-comments"><a href="' . get_comments_link( $post -> ID ) . '"> '. get_comments_number( $post -> ID ) .' </a></p>';
- }
- $result .= '<a href="' . get_permalink( $post -> ID ) . '" title="' . $post -> post_title . '">';
- $result .= '<h4 class="cosmo-category-content-h4">';
- $result .= $post -> post_title ;
- $result .= '</h4>';
- $result .= '<p>';
- $result .= de_excerpt( $post -> post_excerpt , $post -> post_content , CAT_CNT_LN );
- $result .= '</p>';
- $result .= '</a>';
- $result .= '<div class="blog-meta">';
- $result .= '<p class="time">' . date('F j, Y' , strtotime($post -> post_date ) ) . '</p>';
- $result .= '<p class="user"><a href="' . get_author_posts_url( $post-> post_author ) . '">'. get_the_author_meta( 'display_name' , $post-> post_author ) .'</a></p>';
- $result .= '</div>';
- $result .= '</div>';
- $result .= '<ul class="cosmo-posts-more">';
- }else{
- $result .= '<li><a href="' . get_permalink( $post -> ID ) . '" title="' . $post-> post_title . '">'.$post-> post_title.'</a></li>';
- }
- $j++;
- }
- $result .= '</ul>';
- $result .= '</div>';
- if( $classes == 'last' ){
- $result .= '<div class="clearfix border-bottom"></div>';
- if( self::$adds ){
- if( strlen( admin_options::get_values('advertising','zone_2' ) ) ){
- $result .= '<div class="cosmo-ads">';
- $result .= admin_options::get_values('advertising','zone_2' );
- $result .= '</div>';
- self::$adds = false;
- }
- }
- }
- }
- }
- return $result;
- }
- static function get_content_selected_posts( ){
- $query = array();
- $query['paged'] = self::get_page();
- $query['meta_key'] = 'front_page';
- $query['post__not_in'] = get_option( 'sticky_posts' );
- $wp_query = new WP_Query( $query );
- $result = '';
- foreach( $wp_query -> posts as $post ){
- $wp_query -> the_post();
- $result .= '<div class="post" id="post-' . $post -> ID . '">';
- $result .= '<h2 class="entry-title"><a rel="bookmark" title="' . __('Permalink to','cosmotheme') .' '. $post -> post_title . '" href="' . get_permalink( $post -> ID ) . '">' . $post -> post_title . '</a></h2>';
- $meta = get_post_meta($post -> ID, 'meta_post', true); /*check if user has disabled meta data for this specific post/page*/
- if($meta != 'none'){
- $result .= '<div class="blog-meta">';
- $result .= '<p class="time">' . get_the_time('j F Y, H:i', $post -> ID ) . '</p>';
- $result .= '<p class="user"><a href="'.get_author_posts_url( $post-> post_author ).'">'.get_the_author_meta( 'display_name' , $post-> post_author ).'</a></p>';
- ob_start();
- ob_clean();
- edit_post_link( __( 'Edit', 'cosmotheme' ), '<p class="edit_post">', '</p>' );
- $result .= ob_get_clean();
- if ( comments_open( $post -> ID ) ){
- $result .= '<p class="cosmo-comments"><a href="'.get_comments_link( $post -> ID ).'">'.get_comments_number( $post -> ID ).' </a></p>';
- }
- $result .= '</div>';
- }
- $result .= '<div class="b_text">';
- ob_start();
- ob_clean();
- the_content();
- $result .= ob_get_clean();
- $result .= '</div>';
- $tags = wp_get_post_tags( $post -> ID );
- if( !empty( $tags ) ){
- $result .= '<div class="b_tag clearfix">';
- foreach( $tags as $tag ){
- $result .= '<a href="' . get_tag_link( $tag -> term_id ) .'" title="' . __('Permalink to','cosmotheme') .' '. $tag -> name . '"><span>'. $tag -> name .'</span></a>';
- }
- $result .= '</div>';
- }
- $result .= '</div>';
- if( self::$adds ){
- if( strlen( admin_options::get_values('advertising','zone_2' ) ) ){
- $result .= '<div class="cosmo-ads">';
- $result .= admin_options::get_values('advertising','zone_2' );
- $result .= '</div>';
- self::$adds = false;
- }
- }
- }
- wp_reset_query();
- return $result;
- }
- static function get_content_latest_posts( ){
- $query = array();
- $query['paged'] = self::get_page();
- if( admin_options::get_values('front_page' , 'resources') == 'selected_posts' ){
- $query['post__not_in'] = self::get_exclude_posts();
- }
- $query['posts_per_page'] = get_option('posts_per_page');
- $wp_query = new WP_Query( $query );
- $result = '';
- $i = 0;
- foreach( $wp_query -> posts as $post ){
- $wp_query -> the_post();
- $i++;
- $result .= '<div class="post" id="post-' . $post -> ID . '">';
- $result .= '<h2 class="entry-title"><a rel="bookmark" title="' . __('Permalink to','cosmotheme') .' '. $post -> post_title . '" href="' . get_permalink( $post -> ID ) . '">' . $post -> post_title . '</a></h2>';
- $meta = get_post_meta($post -> ID, 'meta_post', true); /*check if user has disabled meta data for this specific post/page*/
- if($meta != 'none'){
- $result .= '<div class="blog-meta">';
- $result .= '<p class="time">' . get_the_time('j F Y, H:i', $post -> ID ) . '</p>';
- $result .= '<p class="user"><a href="'.get_author_posts_url( $post-> post_author ).'">'.get_the_author_meta( 'display_name' , $post-> post_author ).'</a></p>';
- ob_start();
- ob_clean();
- edit_post_link( __( 'Edit', 'cosmotheme' ), '<p class="edit_post">', '</p>' );
- $result .= ob_get_clean();
- if ( comments_open( $post -> ID ) ){
- $result .= '<p class="cosmo-comments"><a href="'.get_comments_link( $post -> ID ).'">'.get_comments_number( $post -> ID ).' </a></p>';
- }
- $result .= '</div>';
- }
- $result .= '<div class="b_text">';
- if( has_post_thumbnail( $post -> ID ) ){
- $result .= '<div class="b_img">';
- $result .= wp_get_attachment_image( get_post_thumbnail_id( $post -> ID ) , '160x120' );
- $args = array(
- 'numberposts' => -1,
- 'post_type' => 'attachment',
- 'status' => 'publish',
- 'post_mime_type' => 'image',
- 'post_parent' => $post -> ID
- );
- $images = &get_children($args);
- if( isset( $images[ get_post_thumbnail_id( $post -> ID ) ] ) ){
- $text = $images[ get_post_thumbnail_id( $post -> ID ) ] -> post_excerpt;
- }else{
- $args = array(
- 'numberposts' => -1,
- 'post_type' => 'attachment',
- 'status' => 'publish',
- 'post_mime_type' => 'image',
- 'post_parent' => 0
- );
- $images = &get_children($args);
- if( isset( $images[ get_post_thumbnail_id( $post -> ID ) ] ) ){
- $text = $images[ get_post_thumbnail_id( $post -> ID ) ] -> post_excerpt;
- }else{
- $text = '';
- }
- }
- $result .= '<span class="img_text">' . $text . '</span>';
- $result .= '</div>';
- }
- $result .= '<p>';
- $result .= de_excerpt( $post -> post_excerpt , $post -> post_content , POST_CNT_LN );
- $result .= '</p>';
- $result .= '</div>';
- $tags = wp_get_post_tags( $post -> ID );
- if( !empty( $tags ) ){
- $result .= '<div class="b_tag clearfix">';
- foreach( $tags as $tag ){
- $result .= '<a href="' . get_tag_link( $tag -> term_id ) .'" title="' . __('Permalink to','cosmotheme') .' '. $tag -> name . '"><span>'. $tag -> name .'</span></a>';
- }
- $result .= '</div>';
- }
- $result .= '<div class="b_but">';
- $result .= '<a href="' . get_permalink( $post -> ID ) . '"><span class="but">' . __('read more','cosmotheme') . '<span> </span></span></a>';
- $result .= '</div>';
- $result .= '</div>';
- if( $i == 3 ){
- if( self::$adds ){
- if( strlen( admin_options::get_values('advertising','zone_2' ) ) ){
- $result .= '<div class="cosmo-ads">';
- $result .= admin_options::get_values('advertising','zone_2' );
- $result .= '</div>';
- self::$adds = false;
- }
- }
- }
- }
- $result .= '<div class="pag">';
- global $wp_rewrite;
- $current = $query['paged'];
- $pagination = array(
- 'base' => @add_query_arg('page','%#%'),
- 'format' => '',
- 'total' => $wp_query->max_num_pages,
- 'current' => $current,
- 'show_all' => false,
- 'type' => 'array'
- );
- if( $wp_rewrite->using_permalinks() )
- $pagination['base'] = user_trailingslashit( trailingslashit( remove_query_arg( 's', get_pagenum_link( 1 ) ) ) . 'page/%#%/', 'paged' );
- if( !empty($wp_query->query_vars['s']) )
- $pagination['add_args'] = array( 's' => get_query_var( 's' ) );
- $pgn = paginate_links( $pagination );
- if( $current == 1 ){
- $current--;
- }
- $result .= '<ul class="b_pag center p_b">';
- if(!empty($pgn)){
- foreach($pgn as $k => $link){
- $result .= '<li>'.str_replace('class="prev ','class="no_link ',str_replace('class="next ','class="no_link ',str_replace("'",'"',$link) ) ).'</li>';
- }
- }
- $result .= '</ul>';
- $result .= '</div>';
- wp_reset_query();
- return $result;
- }
- static function get_exclude_posts(){
- $query['meta_key'] = 'front_page';
- $query['post__not_in'] = get_option( 'sticky_posts' );
- $wp_query = new WP_Query( $query );
- $result = array();
- foreach( $wp_query -> posts as $id => $post ){
- $result[] = $post -> ID;
- }
- return $result;
- }
- static function get_null_content( ){
- $result = '<div class="post">';
- $result .= '<h2 class="entry-title">'. __("Not found posts",'cosmotheme') . '</h2>';
- $result .= '<div class="b_text">';
- $result .= '<p>';
- $result .= __('Please select the categories you want to show','cosmotheme');
- $result .= '<a href="'.home_url('/wp-admin/admin.php?page=settings#front_page_settings').'"> '.__('select categories','cosmotheme').' </a>';
- $result .= '</p>';
- $result .= '</div>';
- $result .= '</div>';
- $result .= '<div class="clearfix" width="100%"></div>';
- return $result;
- }
- static function get_page(){
- if( (int)get_query_var('paged') > (int)get_query_var('page') ){
- $result = (int)get_query_var('paged');
- }else{
- if( (int)get_query_var('page') == 0 ){
- $result = 1;
- }else{
- $result = (int)get_query_var('page');
- }
- }
- return $result;
- }
- static function get_content_page( ){
- $wp_query = new WP_Query('p='.admin_options::get_values( 'front_page' , 'page' ).'&post_type=page');
- foreach( $wp_query -> posts as $post ){
- $wp_query -> the_post();
- $result = '<div class="post main-page-post" id="post-' . $post -> ID . '">';
- $result .= '<div class="b_text"><p>';
- ob_start();
- ob_clean();
- the_content();
- $result .= ob_get_clean();
- $result .= '</p></div>';
- $result .= '</div>';
- }
- wp_reset_query();
- return $result;
- }
- }
- ?>