namespace AMB; if ( ! defined( 'ABSPATH' ) ) exit; function sc_brands_hub( $atts ) { $atts = shortcode_atts([ 'featured' => '0', 'limit' => '50', 'columns' => '', 'layout' => 'cards', // cards|tiles|list 'gap' => '', // px 'title' => '', 'class' => '', ], $atts, 'all_my_brands_hub' ); $limit = max( 1, (int) $atts['limit'] ); $cols_raw = (string) $atts['columns']; $columns = $cols_raw !== '' ? (int) $atts['columns'] : (int) amb_get_option( 'amb_default_brand_columns', 6 ); $columns = min( 6, max( 2, (int) $columns ) ); $meta_query = []; if ( '1' === (string) $atts['featured'] ) { $meta_query[] = [ 'key' => '_amb_brand_featured', 'value' => '1' ]; } $q = new \WP_Query([ 'post_type' => 'mm_brand', 'post_status' => 'publish', 'posts_per_page' => $limit, 'paged' => $page, 'orderby' => [ 'menu_order' => 'ASC', 'title' => 'ASC' ], 'meta_query' => $meta_query, ]); if ( ! $q->have_posts() ) return ''; ob_start(); if ( $atts['title'] ) :

echo esc_html( $atts['title'] );

endif;
while ( $q->have_posts() ) : $q->the_post(); $id = get_the_ID(); $tagline = get_meta( $id, '_amb_brand_tagline' ); $site = get_meta( $id, '_amb_brand_site_url' ); $ig = get_meta( $id, '_amb_brand_instagram' ); $fb = get_meta( $id, '_amb_brand_facebook' ); $tw = get_meta( $id, '_amb_brand_twitter' ); $tt = get_meta( $id, '_amb_brand_tiktok' ); $yt = get_meta( $id, '_amb_brand_youtube' ); $book = get_meta( $id, '_amb_brand_booking_url' ); $link = $site ? $site : get_permalink( $id );
if ( has_post_thumbnail( $id ) ) : echo get_the_post_thumbnail( $id, 'medium', [ 'class' => 'amb-thumb' ] ); else : endif;

echo esc_html( get_the_title( $id ) );

if ( $tagline ) :

echo esc_html( $tagline );

endif;
if ( $site || $ig || $fb || $tw || $tt || $yt || $book ) : endif;
endwhile; wp_reset_postdata();
return ob_get_clean(); } add_shortcode( 'all_my_brands_hub', __NAMESPACE__ . '\sc_brands_hub' ); function build_project_query_args( $base ) { // $base includes: status, limit, brand_id (restriction), url_override bool, filter values $status = sanitize_status( $base['status'] ?? 'upcoming' ); $limit = max( 1, intval( $base['limit'] ?? 12 ) ); $page = max( 1, intval( $base['page'] ?? 1 ) ); $brand_restrict = intval( $base['brand_id'] ?? 0 ); $filters = [ 'brand' => intval( $base['filter_brand'] ?? 0 ), 'type' => intval( $base['filter_type'] ?? 0 ), 'status' => $base['filter_status'] ?? '', 'q' => $base['filter_q'] ?? '', ]; // If URL override enabled, URL params win when present. if ( ! empty( $base['use_url_filters'] ) ) { $u = current_url_filters(); if ( ! empty( $u['page'] ) ) { $page = max( 1, intval( $u['page'] ) ); $args['paged'] = $page; } if ( $u['brand'] ) $filters['brand'] = $u['brand']; if ( $u['type'] ) $filters['type'] = $u['type']; if ( $u['status'] ) $filters['status'] = $u['status']; if ( $u['q'] !== '' ) $filters['q'] = $u['q']; } $args = [ 'post_type' => 'mm_project', 'post_status' => 'publish', 'posts_per_page' => $limit, 'paged' => $page, 'meta_query' => [], ]; // Status: if filter_status present, it overrides the shortcode's status $effective_status = $filters['status'] ? sanitize_status( $filters['status'] ) : $status; $args['meta_query'][] = [ 'key' => '_amb_project_status', 'value' => amb_status_values_for_query( $effective_status ), 'compare' => 'IN', ]; // brand restriction (brand page) if ( $brand_restrict > 0 ) { $args['meta_query'][] = [ 'key' => '_amb_project_brand_ids', 'value' => '"' . $brand_restrict . '"', 'compare' => 'LIKE', ]; } // brand filter if ( $filters['brand'] > 0 ) { $args['meta_query'][] = [ 'key' => '_amb_project_brand_ids', 'value' => '"' . intval($filters['brand']) . '"', 'compare' => 'LIKE', ]; } // project type taxonomy filter if ( $filters['type'] > 0 ) { $args['tax_query'] = [ [ 'taxonomy' => 'mm_project_type', 'field' => 'term_id', 'terms' => [ intval( $filters['type'] ) ], ] ]; } // search if ( $filters['q'] !== '' ) { $args['s'] = sanitize_search( $filters['q'] ); } // Ordering: if ( in_array( $effective_status, [ 'upcoming', 'active' ], true ) ) { $args['meta_key'] = '_amb_project_start_date'; $args['orderby'] = 'meta_value'; $args['order'] = 'ASC'; } else { $args['orderby'] = 'date'; $args['order'] = 'DESC'; } return [ $args, $filters, $effective_status ]; } function render_project_cards( \WP_Query $q, $columns ) { ob_start();
while ( $q->have_posts() ) : $q->the_post(); $id = get_the_ID(); $start_date = get_meta( $id, '_amb_project_start_date' ); $location = get_meta( $id, '_amb_project_location' ); $cta_url = get_meta( $id, '_amb_project_cta_url' ); $brand_ids = get_post_meta( $id, '_amb_project_brand_ids', true ); if ( ! is_array( $brand_ids ) ) $brand_ids = [];
if ( has_post_thumbnail( $id ) ) : echo get_the_post_thumbnail( $id, 'large', [ 'class' => 'amb-thumb' ] ); else : endif;

echo esc_html( get_the_title( $id ) );

if ( $start_date ) : echo esc_html( $start_date ); endif; if ( $location ) : echo esc_html( $location ); endif;
if ( ! empty( $brand_ids ) ) :
foreach ( array_slice( $brand_ids, 0, 4 ) as $bid ) : $title = get_the_title( $bid ); if ( ! $title ) continue; echo esc_html( $title ); endforeach;
endif; if ( has_excerpt( $id ) ) :

echo esc_html( get_the_excerpt( $id ) );

endif;
if ( $cta_url ) : endif;
endwhile; wp_reset_postdata();
return ob_get_clean(); } function sc_projects( $atts ) { $atts = shortcode_atts([ 'status' => 'upcoming', 'limit' => '12', 'columns' => '', 'layout' => 'cards', // cards|tiles|list 'gap' => '', // px 'title' => '', 'per_row' => '', // alias for columns 'class' => '', 'filters' => '0', 'search' => '0', 'brand_id' => '', 'use_url_filters'=> '1', // enable shareable URL filters by default 'ajax' => '1', // enable AJAX updates by default when filters/search displayed 'pagination' => '0', // show next/prev arrows (AJAX) 'page_param' => '', // URL param name for page number (shareable) ], $atts, 'all_my_brands_projects' ); $cols_in = (string)$atts['per_row'] !== '' ? (int)$atts['per_row'] : ((string)$atts['columns'] !== '' ? (int)$atts['columns'] : (int) amb_get_option( 'amb_default_project_columns', 3 )); $columns = min( 4, max( 1, (int) $cols_in ) ); $base = [ 'status' => $atts['status'], 'limit' => (int) $atts['limit'], 'brand_id' => (int) $atts['brand_id'], 'use_url_filters' => (string) $atts['use_url_filters'] === '1', 'filter_brand' => 0, 'filter_type' => 0, 'filter_status' => '', 'filter_q' => '', ]; $page_param = (string) $atts['page_param'] !== '' ? sanitize_key( $atts['page_param'] ) : ( sanitize_status( $atts['status'] ) === 'completed' ? 'amb_page_latest' : 'amb_page_upcoming' ); $page_from_url = 1; if ( (string) $atts['use_url_filters'] === '1' && isset( $_GET[ $page_param ] ) ) { $page_from_url = max( 1, absint( $_GET[ $page_param ] ) ); } $base['page'] = $page_from_url; list($query_args, $filters, $effective_status) = build_project_query_args( $base ); $q = new \WP_Query( $query_args ); if ( ! $q->have_posts() ) { // Still render wrapper if filters UI is on (so user can see filters) if ( (string)$atts['filters'] !== '1' && (string)$atts['search'] !== '1' ) return ''; } // filter options $all_brands = get_posts([ 'post_type' => 'mm_brand', 'post_status' => 'publish', 'posts_per_page' => -1, 'orderby' => [ 'menu_order' => 'ASC', 'title' => 'ASC' ], ]); $types = get_terms([ 'taxonomy' => 'mm_project_type', 'hide_empty' => false, ]); // initial UI values from resolved filters $init_brand = intval( $filters['brand'] ); $init_type = intval( $filters['type'] ); $init_status = $filters['status'] ? sanitize_status( $filters['status'] ) : ''; $init_q = $filters['q']; $wrap_id = 'amb-projects-' . wp_rand( 1000, 9999 ); $nonce = wp_create_nonce( 'amb_ajax_projects' ); ob_start(); if ( $atts['title'] ) :

echo esc_html( $atts['title'] );

endif;
if ( '1' === (string) $atts['filters'] || '1' === (string) $atts['search'] ) :
if ( '1' === (string) $atts['search'] ) : endif; if ( '1' === (string) $atts['filters'] ) : endif;
endif;
if ( $q->have_posts() ) { echo render_project_cards( $q, $columns ); }
$show_pagination = ((string)$atts['pagination'] === '1'); $max_pages = (int) $q->max_num_pages; $cur_page = isset($base['page']) ? (int)$base['page'] : 1; if ( $show_pagination ) :
echo esc_html( sprintf( __( '%1$d / %2$d', 'all-my-brands' ), (int) $cur_page, (int) max( 1, $max_pages ) ) );
endif;

esc_html_e( 'No projects match your filters.', 'all-my-brands' );

return ob_get_clean(); } add_shortcode( 'all_my_brands_projects', __NAMESPACE__ . '\sc_projects' ); function sc_portfolio_page( $atts ) { $atts = shortcode_atts([ 'template' => '', // if set, uses showcase templates (classic|minimal|magazine|hero|masonry) 'brands_title' => '', 'upcoming_title' => '', 'latest_title' => '', 'brands_featured_only'=> '0', 'brands_columns' => '', 'projects_columns' => '', 'upcoming_limit' => '12', 'latest_limit' => '12', 'gap' => '', ], $atts, 'all_my_brands_portfolio' ); if ( (string) $atts['template'] !== '' ) { return do_shortcode( '[amb_showcase template="' . esc_attr( $atts['template'] ) . '"]' ); } $brands_title = $atts['brands_title'] !== '' ? $atts['brands_title'] : (string) amb_get_option( 'amb_label_brands', 'Explore My Brands' ); $upcoming_title = $atts['upcoming_title'] !== '' ? $atts['upcoming_title'] : (string) amb_get_option( 'amb_label_upcoming', 'Upcoming Projects' ); $latest_title = $atts['latest_title'] !== '' ? $atts['latest_title'] : (string) amb_get_option( 'amb_label_latest', 'Latest Projects' ); $brand_cols = (string) $atts['brands_columns'] !== '' ? (int) $atts['brands_columns'] : (int) amb_get_option( 'amb_default_brand_columns', 6 ); $proj_cols = (string) $atts['projects_columns'] !== '' ? (int) $atts['projects_columns'] : (int) amb_get_option( 'amb_default_project_columns', 3 ); $gap = $atts['gap'] !== '' ? (int) $atts['gap'] : null; $out = '
'; $out .= '

' . esc_html( $brands_title ) . '

'; $out .= do_shortcode( '[all_my_brands_hub featured="' . esc_attr( $atts['brands_featured_only'] ) . '" columns="' . esc_attr( $brand_cols ) . '" layout="cards"]' ); $out .= '

' . esc_html( $upcoming_title ) . '

'; $out .= do_shortcode( '[all_my_brands_projects status="upcoming" limit="' . esc_attr( $atts['upcoming_limit'] ) . '" columns="' . esc_attr( $proj_cols ) . '" filters="1" search="1" ajax="1" use_url_filters="1" layout="cards"]' ); $out .= '

' . esc_html( $latest_title ) . '

'; $out .= do_shortcode( '[all_my_brands_projects status="completed" limit="' . esc_attr( $atts['latest_limit'] ) . '" columns="' . esc_attr( $proj_cols ) . '" filters="1" search="1" ajax="1" use_url_filters="1" layout="cards"]' ); $out .= '
'; return $out; } add_shortcode( 'all_my_brands_portfolio', __NAMESPACE__ . '\sc_portfolio_page' ); function sc_showcase( $atts ) { $atts = shortcode_atts([ 'template' => 'classic', // classic|minimal|magazine|hero|masonry 'class' => '', // wording (optional overrides) 'brands_title' => '', 'upcoming_title' => '', 'latest_title' => '', // layout controls 'brands_columns' => '', 'projects_columns' => '', 'gap' => '', // section toggles 'show_upcoming' => '', 'show_latest' => '', 'projects_per_page'=> '', 'brands_per_page' => '', 'projects_pagination' => '', 'brands_pagination' => '', // per page (optional overrides) 'projects_per_page'=> '', 'brands_per_page' => '', // pagination arrows 'projects_pagination' => '', 'brands_pagination' => '', ], $atts, 'amb_showcase' ); $t = sanitize_text_field( $atts['template'] ); if ( ! in_array( $t, [ 'classic','minimal','magazine','hero','masonry' ], true ) ) $t = 'classic'; $brands_title = (string) $atts['brands_title'] !== '' ? (string) $atts['brands_title'] : (string) amb_get_option( 'amb_label_brands', 'Explore My Brands' ); $upcoming_title = (string) $atts['upcoming_title'] !== '' ? (string) $atts['upcoming_title'] : (string) amb_get_option( 'amb_label_upcoming', 'Upcoming Projects' ); $latest_title = (string) $atts['latest_title'] !== '' ? (string) $atts['latest_title'] : (string) amb_get_option( 'amb_label_latest', 'Latest Projects' ); $brand_cols = (string) $atts['brands_columns'] !== '' ? (int) $atts['brands_columns'] : (int) amb_get_option( 'amb_default_brand_columns', 6 ); $proj_cols = (string) $atts['projects_columns'] !== '' ? (int) $atts['projects_columns'] : (int) amb_get_option( 'amb_default_project_columns', 3 ); $gap_attr = (string) $atts['gap'] !== '' ? ' gap="' . (int) $atts['gap'] . '"' : ''; $gap_style = (string) $atts['gap'] !== '' ? ' ' . amb_css_vars( (int) $atts['gap'] ) : ''; // Defaults pulled from Settings (with per-template overrides) $proj_pp_global = (int) amb_get_option( 'amb_projects_per_page', 18 ); $brand_pp_global = (int) amb_get_option( 'amb_brands_per_page', 24 ); $proj_pp_tpl = (int) amb_get_option( 'amb_tpl_' . $t . '_projects_per_page', 0 ); $brand_pp_tpl = (int) amb_get_option( 'amb_tpl_' . $t . '_brands_per_page', 0 ); $projects_per_page = (string) $atts['projects_per_page'] !== '' ? (int) $atts['projects_per_page'] : ( $proj_pp_tpl > 0 ? $proj_pp_tpl : $proj_pp_global ); $brands_per_page = (string) $atts['brands_per_page'] !== '' ? (int) $atts['brands_per_page'] : ( $brand_pp_tpl > 0 ? $brand_pp_tpl : $brand_pp_global ); $show_upcoming = (string) $atts['show_upcoming'] !== '' ? ( (string) $atts['show_upcoming'] !== '0' ) : (bool) amb_get_option( 'amb_show_upcoming_default', true ); $show_latest = (string) $atts['show_latest'] !== '' ? ( (string) $atts['show_latest'] !== '0' ) : (bool) amb_get_option( 'amb_show_latest_default', true ); $proj_pag = (string) $atts['projects_pagination'] !== '' ? ( (string) $atts['projects_pagination'] !== '0' ) : (bool) amb_get_option( 'amb_enable_projects_pagination', true ); $brand_pag = (string) $atts['brands_pagination'] !== '' ? ( (string) $atts['brands_pagination'] !== '0' ) : (bool) amb_get_option( 'amb_enable_brands_pagination', false ); $proj_pag_attr = $proj_pag ? ' pagination="1"' : ''; $brand_pag_attr = $brand_pag ? ' pagination="1"' : ''; $brand_cols = (int) max( 1, min( 6, $brand_cols ) ); $proj_cols = (int) max( 1, min( 4, $proj_cols ) ); if ( $t === 'hero' ) { $out = '
'; $out .= '
'; $out .= '

' . esc_html( $brands_title ) . '

'; $out .= '

' . esc_html__( 'Explore brands, then dive into the projects.', 'all-my-brands' ) . '

'; $out .= '
'; $out .= '
'; $out .= '

' . esc_html( $brands_title ) . '

'; $out .= do_shortcode( '[all_my_brands_hub columns="' . $brand_cols . '" limit="' . (int) $brands_per_page . '" layout="tiles"' . $brand_pag_attr . $gap_attr . ']' ); $out .= '
'; $out .= '
'; if ( $show_upcoming ) { $out .= '

' . esc_html( $upcoming_title ) . '

'; if ( (bool) amb_get_option( 'amb_tag_cloud_enabled', true ) ) { $out .= do_shortcode( '[amb_tag_cloud title="Tags" ]' ); } $out .= do_shortcode( '[all_my_brands_projects status="upcoming" limit="' . (int) $projects_per_page . '" columns="' . $proj_cols . '" layout="cards" page_param="amb_page_upcoming"' . $proj_pag_attr . $gap_attr . ']' ); } if ( $show_latest ) { $out .= '

' . esc_html( $latest_title ) . '

'; $out .= do_shortcode( '[all_my_brands_projects status="completed" limit="' . (int) $projects_per_page . '" columns="' . $proj_cols . '" layout="tiles" page_param="amb_page_latest"' . $proj_pag_attr . $gap_attr . ']' ); } $out .= '
'; $out .= '
'; return $out; } if ( $t === 'magazine' ) { $out = '
'; // Brands (top) $out .= '
'; $out .= '

' . esc_html( $brands_title ) . '

'; $out .= do_shortcode( '[all_my_brands_hub columns="' . $brand_cols . '" limit="' . (int) $brands_per_page . '" layout="tiles"' . $brand_pag_attr . $gap_attr . ']' ); $out .= '
'; // Projects (bottom) $out .= '
'; if ( $show_upcoming ) { $out .= '

' . esc_html( $upcoming_title ) . '

'; if ( (bool) amb_get_option( 'amb_tag_cloud_enabled', true ) ) { $out .= do_shortcode( '[amb_tag_cloud title="Tags" ]' ); } $out .= do_shortcode( '[all_my_brands_projects status="upcoming" limit="' . (int) $projects_per_page . '" columns="' . $proj_cols . '" layout="list" page_param="amb_page_upcoming"' . $proj_pag_attr . $gap_attr . ']' ); } if ( $show_latest ) { $out .= '

' . esc_html( $latest_title ) . '

'; $out .= do_shortcode( '[all_my_brands_projects status="completed" limit="' . (int) $projects_per_page . '" columns="' . $proj_cols . '" layout="tiles" page_param="amb_page_latest"' . $proj_pag_attr . $gap_attr . ']' ); } $out .= '
'; $out .= '
'; return $out; } if ( $t === 'minimal' ) { $out = '
'; $out .= '

' . esc_html( $brands_title ) . '

'; $out .= do_shortcode( '[all_my_brands_hub columns="' . $brand_cols . '" limit="' . (int) $brands_per_page . '" layout="list"' . $brand_pag_attr . $gap_attr . ']' ); if ( $show_upcoming ) { $out .= '

' . esc_html( $upcoming_title ) . '

'; if ( (bool) amb_get_option( 'amb_tag_cloud_enabled', true ) ) { $out .= do_shortcode( '[amb_tag_cloud title="Tags" ]' ); } $out .= do_shortcode( '[all_my_brands_projects status="upcoming" limit="' . (int) $projects_per_page . '" columns="' . $proj_cols . '" layout="list" page_param="amb_page_upcoming"' . $proj_pag_attr . $gap_attr . ']' ); } if ( $show_latest ) { $out .= '

' . esc_html( $latest_title ) . '

'; $out .= do_shortcode( '[all_my_brands_projects status="completed" limit="' . (int) $projects_per_page . '" columns="' . $proj_cols . '" layout="tiles" page_param="amb_page_latest"' . $proj_pag_attr . $gap_attr . ']' ); } $out .= '
'; return $out; } if ( $t === 'masonry' ) { $out = '
'; $out .= '

' . esc_html( $brands_title ) . '

'; $out .= do_shortcode( '[all_my_brands_hub columns="' . $brand_cols . '" limit="' . (int) $brands_per_page . '" layout="tiles"' . $brand_pag_attr . $gap_attr . ']' ); if ( $show_upcoming ) { $out .= '

' . esc_html( $upcoming_title ) . '

'; if ( (bool) amb_get_option( 'amb_tag_cloud_enabled', true ) ) { $out .= do_shortcode( '[amb_tag_cloud title="Tags" ]' ); } $out .= do_shortcode( '[all_my_brands_projects status="upcoming" limit="' . (int) $projects_per_page . '" columns="' . $proj_cols . '" layout="tiles" page_param="amb_page_upcoming"' . $proj_pag_attr . $gap_attr . ']' ); } if ( $show_latest ) { $out .= '

' . esc_html( $latest_title ) . '

'; $out .= do_shortcode( '[all_my_brands_projects status="completed" limit="' . (int) $projects_per_page . '" columns="' . $proj_cols . '" layout="tiles" page_param="amb_page_latest"' . $proj_pag_attr . $gap_attr . ']' ); } $out .= '
'; return $out; } // Classic default $out = '
'; $out .= '

' . esc_html( $brands_title ) . '

'; $out .= do_shortcode( '[all_my_brands_hub columns="' . $brand_cols . '" limit="' . (int) $brands_per_page . '" layout="cards"' . $brand_pag_attr . $gap_attr . ']' ); if ( $show_upcoming ) { $out .= '

' . esc_html( $upcoming_title ) . '

'; if ( (bool) amb_get_option( 'amb_tag_cloud_enabled', true ) ) { $out .= do_shortcode( '[amb_tag_cloud title="Tags" ]' ); } $out .= do_shortcode( '[all_my_brands_projects status="upcoming" limit="' . (int) $projects_per_page . '" columns="' . $proj_cols . '" layout="cards" page_param="amb_page_upcoming"' . $proj_pag_attr . $gap_attr . ']' ); } if ( $show_latest ) { $out .= '

' . esc_html( $latest_title ) . '

'; $out .= do_shortcode( '[all_my_brands_projects status="completed" limit="' . (int) $projects_per_page . '" columns="' . $proj_cols . '" layout="tiles" page_param="amb_page_latest"' . $proj_pag_attr . $gap_attr . ']' ); } $out .= '
'; return $out; } add_shortcode( 'amb_showcase', __NAMESPACE__ . '\sc_showcase' ); function sc_amb_portfolio( $atts ) { $atts = shortcode_atts([ 'template' => '', // classic|minimal|magazine|hero|masonry // wording 'brands_title' => '', 'upcoming_title' => '', 'latest_title' => '', // layout 'brands_columns' => '', 'projects_columns' => '', 'gap' => '', // toggles 'show_upcoming' => '', 'show_latest' => '', // per page 'brands_per_page' => '', 'projects_per_page' => '', // pagination 'projects_pagination' => '', 'brands_pagination' => '', 'class' => '', ], $atts, 'amb_portfolio' ); $tpl = $atts['template'] !== '' ? sanitize_text_field( $atts['template'] ) : (string) amb_get_option( 'amb_default_template', 'classic' ); if ( ! in_array( $tpl, [ 'classic','minimal','magazine','hero','masonry' ], true ) ) { $tpl = 'classic'; } $pairs = [ 'template' => $tpl ]; foreach ( [ 'brands_title','upcoming_title','latest_title','brands_columns','projects_columns','gap','show_upcoming','show_latest','brands_per_page','projects_per_page','projects_pagination','brands_pagination','class' ] as $k ) { if ( isset( $atts[ $k ] ) && (string) $atts[ $k ] !== '' ) { $pairs[ $k ] = $atts[ $k ]; } } $parts = []; foreach ( $pairs as $k => $v ) { $parts[] = $k . '="' . esc_attr( $v ) . '"'; } return do_shortcode( '[amb_showcase ' . implode( ' ', $parts ) . ']' ); } add_shortcode( 'amb_portfolio', __NAMESPACE__ . '\sc_amb_portfolio' ); /** * Tag cloud / chips for Portfolio Tags taxonomy. * Usage: [amb_tag_cloud taxonomy="amb_portfolio_tag" style="chips|cloud"] */ function sc_amb_tag_cloud( $atts ) { $atts = shortcode_atts([ 'taxonomy' => 'amb_portfolio_tag', 'style' => 'chips', 'title' => '', 'class' => '', ], $atts, 'amb_tag_cloud' ); $tax = sanitize_key( $atts['taxonomy'] ); if ( ! taxonomy_exists( $tax ) ) return ''; $terms = get_terms([ 'taxonomy' => $tax, 'hide_empty' => true ]); if ( is_wp_error( $terms ) || empty( $terms ) ) return ''; $current = isset($_GET['amb_tag']) ? sanitize_title( wp_unslash($_GET['amb_tag']) ) : ''; $base_url = remove_query_arg([ 'amb_tag', 'amb_page_upcoming', 'amb_page_latest' ]); $gold = (bool) amb_get_option( 'amb_tag_cloud_gold', true ); $out = '
'; if ( $atts['title'] !== '' ) { $out .= '
' . esc_html( $atts['title'] ) . '
'; } if ( $current ) { $out .= '' . esc_html__( 'All', 'all-my-brands' ) . ''; } else { $out .= '' . esc_html__( 'All', 'all-my-brands' ) . ''; } foreach ( $terms as $t ) { $url = add_query_arg( 'amb_tag', $t->slug, $base_url ); $active = $current === $t->slug; $out .= '' . esc_html( $t->name ) . ''; } $out .= '
'; return $out; } add_shortcode( 'amb_tag_cloud', __NAMESPACE__ . '\sc_amb_tag_cloud' ); function amb_trim_chars( $text, $limit ) { $limit = absint( $limit ); $text = wp_strip_all_tags( (string) $text ); $text = trim( preg_replace( '/\s+/', ' ', $text ) ); if ( $limit <= 0 ) return ''; if ( function_exists( 'mb_strlen' ) ) { if ( mb_strlen( $text ) <= $limit ) return $text; return mb_substr( $text, 0, $limit ) . '…'; } if ( strlen( $text ) <= $limit ) return $text; return substr( $text, 0, $limit ) . '…'; } function amb_get_card_desc( $post_id ) { $mode = amb_get_option( 'amb_desc_mode', 'excerpt' ); if ( $mode === 'none' ) return ''; $limit = absint( amb_get_option( 'amb_desc_char_limit', 140 ) ); $text = get_the_excerpt( $post_id ); if ( $text === '' ) { $text = wp_strip_all_tags( get_post_field( 'post_content', $post_id ) ); } return amb_trim_chars( $text, $limit ); }