Need some expert advise/help on an filtered blog post code !!
-
I have an issue with a filtered blog post page where I would like to show in the filtered menu certain category id’s but where underneath all the posts should be shown. The code where I have to look is this one (according to the designer of the theme, who does not know the answer to my question). The website I am working on can be seen here:
https://bit.ly/17tFLMEThe issue is … it is for a news site where there are many categories but I only want some of them to be shown in the filtered menu but all posts underneath in the grid layout. Difficult? Not posible?
<?php $title = $grid_columns_count = $grid_teasers_count = $grid_layout = ''; $grid_template = $grid_thumb_size = $grid_posttypes = $grid_layout_mode = $grid_taxomonies = $grid_categories = ''; $width = $orderby = $order = $isotope_item = $carousel=''; extract(shortcode_atts(array( 'title' => '', 'grid_columns_count' => 4, 'grid_teasers_count' => 8, 'grid_layout' => 'thumbnail_caption', 'grid_template' => 'grid', //grid, carousel 'grid_thumb_size' => 'blog', 'grid_posttypes' => '', 'grid_taxomonies' => '', 'grid_categories' => '', 'grid_excerpt_length' => '', 'grid_layout_mode' => 'fitRows', 'width' => '1/1', 'orderby' => NULL, 'order' => 'DESC', 'meta_info_large' => '' ), $atts)); if ( $grid_template == 'grid' || $grid_template == 'filtered_grid') { wp_enqueue_style('isotope-css'); wp_enqueue_script( 'isotope' ); $isotope_item = 'isotope-item '; } else if ( $grid_template == 'carousel' ) { $isotope_item = ''; } $output = ''; $width = ''; $li_span_class = wpb_translateColumnsCountToSpanClass( $grid_columns_count ); $query_args = array(); // Post teasers count if ( $grid_teasers_count != '' && !is_numeric($grid_teasers_count) ) $grid_teasers_count = -1; if ( $grid_teasers_count != '' && is_numeric($grid_teasers_count) ) $query_args['posts_per_page'] = $grid_teasers_count; // Post types $pt = array(); if ( $grid_posttypes != '' ) { $grid_posttypes = explode(",", $grid_posttypes); foreach ( $grid_posttypes as $post_type ) { array_push($pt, $post_type); } $query_args['post_type'] = $pt; } // Taxonomies $taxonomies = array(); if ( $grid_taxomonies != '' ) { $grid_taxomonies = explode(",", $grid_taxomonies); foreach ( $grid_taxomonies as $taxom ) { array_push($taxonomies, $taxom); } } // Narrow by categories if ( $grid_categories != '' ) { $grid_categories = explode(",", $grid_categories); $gc = array(); foreach ( $grid_categories as $grid_cat ) { array_push($gc, $grid_cat); } $gc = implode(",", $gc); ////https://snipplr.com/view/17434/wordpress-get-category-slug/ $query_args['category_name'] = $gc; $taxonomies = get_taxonomies('', 'object'); $query_args['tax_query'] = array('relation' => 'OR'); foreach ( $taxonomies as $t ) { if ( in_array($t->object_type[0], $pt) ) { $query_args['tax_query'][] = array( 'taxonomy' => $t->name,//$t->name,//'portfolio_category', 'terms' => $grid_categories, 'field' => 'slug', ); } } } // Order posts if ( $orderby != NULL ) { $query_args['orderby'] = $orderby; } $query_args['order'] = $order; // Run query $my_query = new WP_Query($query_args); $teasers = ''; $teaser_categories = Array(); if($grid_template == 'filtered_grid' && empty($grid_taxomonies)) { $taxonomies = get_object_taxonomies(!empty($query_args['post_type']) ? $query_args['post_type'] : get_post_types(array('public' => false, 'name' => 'attachment'), 'names', 'NOT')); } $posts_Ids = array(); while ( $my_query->have_posts() ) { $link_title_start = $link_image_start = $p_link = $link_image_end = ''; $my_query->the_post(); $posts_Ids[] = $my_query->post->ID; $categories_css = ''; if( $grid_template == 'filtered_grid' ) { $post_categories = wp_get_object_terms($my_query->post->ID, $taxonomies); foreach($post_categories as $cat) { if(!in_array($cat->term_id, $teaser_categories)) { $teaser_categories[] = $cat->term_id; } $categories_css .= ' grid-cat-'.$cat->term_id; } } $post_title = the_title("", "", false); $post_id = $my_query->post->ID; $teaser_post_type = 'posts_grid_teaser_'.$my_query->post->post_type . ' '; // Thumbnail logic $thumbnail = ''; if ( in_array($grid_layout, array('thumbnail_caption', 'thumbnail_title_excerpt') ) ) { $post_thumbnail = ''; $post_thumbnail = wpb_getImageBySize(array( 'post_id' => $post_id, 'thumb_size' => $grid_thumb_size )); $thumbnail = $post_thumbnail['thumbnail']; } /* Caption Logic */ $format=''; $videoURL = get_post_meta($post_id, 'reedwan_video_url', TRUE); if ( 'post' == get_post_type() ) { if(has_post_format('video') && $videoURL){ $format='<a href="'.$videoURL.'" title="'.__('Play Video', 'realnews').'" class="play-video caption-type"><i class="icon-play-1"></i></a>';} else if(has_post_format('audio') && $size='big' && $size!='small'){$format='<a class="caption-type" href="'.get_permalink( get_the_ID() ).'" title="'.__('Play Music', 'realnews').'"><i class="icon-note-beamed"></i></a>';} else{$format='';} } /* Sticky */ $sticky=''; if ( is_sticky()){$sticky='<a href="'.get_permalink( get_the_ID() ).'" title="'.__('Featured Post','realnews').'" class="sticky-post"><i class="icon-star"></i></a>';} /* Excerpt */ $excerpt =''; if($grid_excerpt_length!='' || $grid_excerpt_length!=0 && $grid_layout == 'thumbnail_title_excerpt') { $excerpt = '<p>'.string_limit_words(get_the_excerpt(),$grid_excerpt_length).'</p>'; } /* Meta */ $meta =''; if($meta_info_large==true) { $meta .= '<div class="detailmeta">'; $meta .= '<span class="time"><i class="icon-clock"></i>'.get_the_time('F j, Y').'</span>'; $meta .= taqyeem_get_score_alternate(get_the_ID(), 'small'); $meta .= '</div>'; } /* Caption */ $caption=''; if ( $grid_layout == 'thumbnail_caption' ){ $caption = '<div class="hover-caption-thumb"><a href="'.get_permalink( get_the_ID() ).'" class="caption-link" title="'.the_title_attribute( 'echo=0' ).'">'.the_title_attribute( 'echo=0' ).'</a></div>'; } $link_image_start = $link_title_start = '<a class="link_title" href="'.get_permalink($post_id).'" title="'.sprintf( esc_attr__( 'Permalink to %s', 'js_composer' ), the_title_attribute( 'echo=0' ) ).'">'; $link_title_end = $link_image_end = '</a>'; $teasers .= '<li class="builder_grid '.$isotope_item.apply_filters(VC_SHORTCODE_CUSTOM_CSS_FILTER_TAG, $li_span_class, 'vc_teaser_grid_li').$categories_css.'">'; // If grid layout is: Thumbnail + Captions if ( $grid_layout == 'thumbnail_caption' ) { if ( $thumbnail ) { $to_filter = '<div class="mediaholder">' .$format . $sticky .'<a href="'.get_permalink($post_id).'">'.$thumbnail . '</a>'. $caption .'</div>'; $teasers .= apply_filters('vc_teaser_grid_thumbnail', $to_filter, array("grid_layout" => $grid_layout, "ID" => $post_id, "thumbnail" => $thumbnail) ); } } // If grid layout is: Thumbnail + Title + Excerpt if ( $grid_layout == 'thumbnail_title_excerpt' ) { if ( $thumbnail ) { $to_filter = '<div class="mediaholder">' .$format . $sticky.'<a href="'.get_permalink($post_id).'">' . $thumbnail . '</a></div>'; $teasers .= apply_filters('vc_teaser_grid_thumbnail', $to_filter, array("grid_layout" => $grid_layout, "ID" => $post_id, "thumbnail" => $thumbnail) ); } if ( $post_title ) { $to_filter = '<div class="detailholder"><h4>' . $link_title_start . $post_title . $link_title_end . '</h4>'.$excerpt.$meta.'</div>'; $teasers .= apply_filters('vc_teaser_grid_title', $to_filter, array("grid_layout" => $grid_layout, "ID" => $post_id, "title" => $post_title) ); } } $teasers .= '</li> ' . $this->endBlockComment('single teaser'); } // endwhile loop wp_reset_query(); if( $grid_template == 'filtered_grid' && $teasers && !empty($teaser_categories)) { $categories_array = get_terms($taxonomies, array( 'orderby' => 'name', 'include' => implode(',', $teaser_categories) )); $categories_list_output = '<ul class="categories_filter clearfix">'; $categories_list_output .= '<li class="active"><a href="#" data-filter="*">' . __('All', 'js_composer') . '</a></li>'; foreach($categories_array as $cat) { $categories_list_output .= '<li><a href="#" data-filter=".grid-cat-'.$cat->term_id.'">' . esc_attr($cat->name) . '</a></li>'; } $categories_list_output.= '</ul><div class="clearfix"></div>'; } else { $categories_list_output = ''; } if ( $teasers ) { if ( $grid_template == 'carousel' ) { $carousel = apply_filters( 'vc_teaser_grid_carousel_arrows', '<div class="carousel-nav"><a href="#" class="prev icon-left-open-big"></a> <a href="#" class="next icon-right-open-big"></a></div>' ); } $teasers = '<div class="teaser_grid_container">'.$categories_list_output. $carousel.'<ul class="wpb_thumbnails wpb_thumbnails-fluid clearfix" data-layout-mode="'.$grid_layout_mode.'">'. $teasers .'</ul></div>'; } else { $teasers = __("Nothing found." , "js_composer"); } $posttypes_teasers = ''; if ( is_array($grid_posttypes) ) { $posttypes_teasers_ar = $grid_posttypes; foreach ( $posttypes_teasers_ar as $post_type ) { $posttypes_teasers .= 'wpb_teaser_grid_'.$post_type . ' '; } } $grid_class = 'wpb_'.$grid_template . ' columns_count_'.$grid_columns_count . ' grid_layout-'.$grid_layout . ' ' . $grid_layout.'_'.$li_span_class . ' ' . 'columns_count_'.$grid_columns_count.'_'.$grid_layout . ' ' . $posttypes_teasers; $css_class = apply_filters(VC_SHORTCODE_CUSTOM_CSS_FILTER_TAG, 'wpb_teaser_grid wpb_content_element '.$grid_class.$width, $this->settings['base']); $output .= "\n\t".'<div class="'.$css_class.' block clearfix">'; $output .= "\n\t\t".'<div class="wpb_wrapper">'; $output .= wpb_widget_title(array('title' => $title, 'extraclass' => 'wpb_teaser_grid_heading')); $output .= $teasers; $output .= "\n\t\t".'</div> '.$this->endBlockComment('.wpb_wrapper'); $output .= "\n\t".'</div> '.$this->endBlockComment('.wpb_teaser_grid'); echo $output;
I am not sure where to look and what to place, if all posible. Personally I also think this next code is in need of change but still, no sure what to put here and if it is posible to do such a thing.
<?php /** * Create filter * {{ */ if( $filter === 'yes' && !empty($this->filter_categories)): $categories_array = $this->getFilterCategories(); ?> <ul class="categories_filter clearfix"> <li class="active"><a href="#" data-filter="*"><?php _e('All', 'js_composer') ?></a></li> <?php foreach($this->getFilterCategories() as $cat): ?> <li><a href="#" data-filter=".grid-cat-<?php echo $cat->term_id ?>"><?php echo esc_attr($cat->name) ?></a></li> <?php endforeach; ?> </ul><div class="clearfix"></div> <?php endif; ?>
I am sort of a newbie but eager to learn but in need of some help.
Thanks anyone. Regards, Remco
- The topic ‘Need some expert advise/help on an filtered blog post code !!’ is closed to new replies.