I have a need to be able to customize which categories are displayed through the portfolio template. Hopefully something i can add manually to one of these tags? I have duplicated the Portfolio template so I can adjust it for a few different pages and create multiple templates.
This is for a furniture company with categories as follows:
Style category name parent (Milan) > Type of Furniture category (Chair) > Chair Product (product page ie portfolio page using the tags "Milan, Chair")
I have a need to be able to customize which categories are displayed through the portfolio template. Hopefully something i can add manually to one of these tags? I have duplicated the Portfolio template so I can adjust it for a few different pages and create multiple templates.
This is for a furniture company with categories as follows:
Style category name parent (Milan) > Type of Furniture category (Chair) > Chair Product (product page ie portfolio page using the tags "Milan, Chair")
<!-- Portfolio Filters --> <ul id="filters" class="<?php echo sanitize_html_class( $soho_filters_class ); ?>"> <li class="filter-line"></li> <li><a id="all" href="#" data-filter="*" class="active"><?php esc_html_e('All', 'soho'); ?></a></li> <?php $soho_portfolio_category = get_terms('portfolio_category', array( 'hide_empty' => 0 )); if($soho_portfolio_category){ foreach($soho_portfolio_category as $portfolio_cat){ ?> <li><a href="#" data-filter=".<?php echo sanitize_title( $portfolio_cat->slug ); ?>"><?php echo wp_kses_post( $portfolio_cat->name ); ?></a></li> <?php } } ?> </ul> <!--/Portfolio Filters --> <!-- Portfolio --> <div id="portfolio-wrap" class="<?php echo esc_attr( $soho_margins ); ?>"> <div id="portfolio" <?php if( $soho_use_lightbox ){ echo 'class="mfp-gallery"'; } ?> data-col="<?php echo esc_attr( $soho_columns ); ?>"> <?php $soho_paged = (get_query_var('paged')) ? get_query_var('paged') : 1; $soho_args = array( 'post_type' => 'soho_portfolio', 'paged' => $soho_paged, 'posts_per_page' => $soho_max_items, ); $soho_portfolio = new WP_Query( $soho_args ); while( $soho_portfolio->have_posts() ){ $soho_portfolio->the_post(); if( $soho_use_lightbox ){ get_template_part('sections/portfolio_section_lightbox_item'); } else { get_template_part('sections/portfolio_section_item'); } } wp_reset_postdata(); ?> </div> </div> <!--/Portfolio -->This, I think, can be done in two steps
first is to display only the categories you want.
get rid of the
<?php $soho_portfolio_category = get_terms('portfolio_category', array( 'hide_empty' => 0 )); if($soho_portfolio_category){ foreach($soho_portfolio_category as $portfolio_cat){ ?> <li><a href="#" data-filter=".<?php echo sanitize_title( $portfolio_cat->slug ); ?>"><?php echo wp_kses_post( $portfolio_cat->name ); ?></a></li> <?php } } ?>and add the category manually as an <li> element with category slug and title
Second step is to select the portfolio items belonging only to those categories
$soho_args = array( 'post_type' => 'soho_portfolio', 'paged' => $soho_paged, 'posts_per_page' => $soho_max_items, );so you need to modify query arguments
https://codex.wordpress.org/Class_Reference/WP_Query#Taxonomy_Parameters
see 'Multiple taxonomy handling'
Thanks
Thank you.
Clapat Support
Review Envato Item Support Policy
Follow us!
https://www.clapat.com/
https://www.facebook.com/clapat.ro
https://www.instagram.com/clapat.themes/
https://x.com/clapatdesign
https://www.linkedin.com/company/clapatstudio
https://www.tiktok.com/@clapatstudio
Ok sounds good... but i cannot get it to work... am I missing something?
<li><a id="all" href="#" data-filter="*" class="active"><?php esc_html_e('All', 'soho'); ?></a></li> <!-- CUSTOM Filters --> <li><a id="#" href=".milan" data-filter="milan"><?php esc_html_e('Milan', 'soho'); ?></a></li> </ul> <!--/Portfolio Filters --> <!-- Portfolio --> <div id="portfolio-wrap" class="<?php echo esc_attr( $soho_margins ); ?>"> <div id="portfolio" <?php if( $soho_use_lightbox ){ echo 'class="mfp-gallery"'; } ?> data-col="<?php echo esc_attr( $soho_columns ); ?>"> <?php $soho_paged = (get_query_var('paged')) ? get_query_var('paged') : 1; $soho_args = array( 'post_type' => 'soho_portfolio', 'paged' => $soho_paged, 'posts_per_page' => $soho_max_items, 'tax_query' => array( 'relation' => 'AND', array( 'taxonomy' => 'category', 'field' => 'slug', 'terms' => array( 'milan', 'milan-chairs', ), ), ), ); $soho_portfolio = new WP_Query( $soho_args ); while( $soho_portfolio->have_posts() ){ $soho_portfolio->the_post(); if( $soho_use_lightbox ){ get_template_part('sections/portfolio_section_lightbox_item'); } else { get_template_part('sections/portfolio_section_item'); } } wp_reset_postdata(); ?>So I finally got this to work... I needed to have the right taxonomy.
<?php $soho_paged = (get_query_var('paged')) ? get_query_var('paged') : 1; $soho_args = array( 'post_type' => 'soho_portfolio', 'paged' => $soho_paged, 'posts_per_page' => $soho_max_items, //Custom category displayed 'tax_query' => array( array( 'taxonomy' => 'portfolio_category', 'field' => 'slug', 'terms' => array( 'patriarch_milan'), ), ), ); $soho_portfolio = new WP_Query( $soho_args ); while( $soho_portfolio->have_posts() ){ $soho_portfolio->the_post(); if( $soho_use_lightbox ){ get_template_part('sections/portfolio_section_lightbox_item'); } else { get_template_part('sections/portfolio_section_item'); } } wp_reset_postdata(); ?>Nice!
Thank you.
Clapat Support
Review Envato Item Support Policy
Follow us!
https://www.clapat.com/
https://www.facebook.com/clapat.ro
https://www.instagram.com/clapat.themes/
https://x.com/clapatdesign
https://www.linkedin.com/company/clapatstudio
https://www.tiktok.com/@clapatstudio