| 1 |
<?php |
| 2 |
/** |
| 3 |
* Portfolio Projects |
| 4 |
* |
| 5 |
* @var $attributes - attributes |
| 6 |
* @var $options - options |
| 7 |
* |
| 8 |
* @link https://codesupply.co |
| 9 |
* @since 1.0.0 |
| 10 |
* |
| 11 |
* @package Sight |
| 12 |
*/ |
| 13 |
|
| 14 |
$class_name = sight_portfolio_area_classes( $attributes, $options ); |
| 15 |
|
| 16 |
// Args Query. |
| 17 |
$args_query = array( |
| 18 |
'post_type' => $attributes['projects_filter_post_type'], |
| 19 |
'ignore_sticky_posts' => true, |
| 20 |
'posts_per_page' => $attributes['number_items'], |
| 21 |
); |
| 22 |
|
| 23 |
// Filter Categories. |
| 24 |
if ( 'sight-projects' === $attributes['projects_filter_post_type'] ) { |
| 25 |
|
| 26 |
if ( isset( $attributes['projects_filter_categories'] ) ) { |
| 27 |
$filter_categories = $attributes['projects_filter_categories']; |
| 28 |
|
| 29 |
if ( $filter_categories ) { |
| 30 |
$args_query['tax_query'][] = array( |
| 31 |
'taxonomy' => 'sight-categories', |
| 32 |
'field' => 'id', |
| 33 |
'terms' => $filter_categories, |
| 34 |
); |
| 35 |
|
| 36 |
$args_query['tax_query']['relation'] = 'OR'; |
| 37 |
} |
| 38 |
} |
| 39 |
} |
| 40 |
|
| 41 |
// Filter Offset. |
| 42 |
if ( isset( $attributes['projects_filter_offset'] ) ) { |
| 43 |
$args_query['offset'] = (int) $attributes['projects_filter_offset']; |
| 44 |
} |
| 45 |
|
| 46 |
// Filter Orderby. |
| 47 |
if ( $attributes['projects_orderby'] ) { |
| 48 |
$type_post_views = sight_post_views_enabled(); |
| 49 |
// Order by Views. |
| 50 |
if ( $type_post_views && 'views' === $attributes['projects_orderby'] ) { |
| 51 |
$args_query['orderby'] = $type_post_views; |
| 52 |
// Don't hide posts without views. |
| 53 |
$args_query['views_query']['hide_empty'] = false; |
| 54 |
|
| 55 |
} else { |
| 56 |
$args_query['orderby'] = $attributes['projects_orderby']; |
| 57 |
} |
| 58 |
} |
| 59 |
|
| 60 |
// Filter Order. |
| 61 |
if ( $attributes['projects_order'] ) { |
| 62 |
$args_query['order'] = $attributes['projects_order']; |
| 63 |
} |
| 64 |
|
| 65 |
/** ---------------------------------- */ |
| 66 |
/** ---------------------------------- */ |
| 67 |
|
| 68 |
// WP Query. |
| 69 |
$portfolio_list = new WP_Query( $args_query ); |
| 70 |
|
| 71 |
// WP Query Data. |
| 72 |
if ( isset( $options['pagination_type'] ) ) { |
| 73 |
$portfolio_list->pagination_type = $options['pagination_type']; |
| 74 |
} else { |
| 75 |
$portfolio_list->pagination_type = 'none'; |
| 76 |
} |
| 77 |
|
| 78 |
// Theme data. |
| 79 |
$data = array( |
| 80 |
'is_sight_query' => true, |
| 81 |
'max_num_pages' => $portfolio_list->max_num_pages, |
| 82 |
'pagination_type' => $portfolio_list->pagination_type, |
| 83 |
'query_vars' => $portfolio_list->query, |
| 84 |
); |
| 85 |
|
| 86 |
$args = sight_portfolio_get_load_more_args( $data, $attributes, $options ); |
| 87 |
|
| 88 |
// Set posts per page. |
| 89 |
$args['posts_per_page'] = $args_query['posts_per_page']; |
| 90 |
|
| 91 |
$query_data = sight_encode_data( $args ); |
| 92 |
|
| 93 |
if ( $portfolio_list->have_posts() ) { |
| 94 |
?> |
| 95 |
<div class="<?php echo esc_attr( $class_name ); ?>" data-items-area="<?php echo esc_attr( $query_data ); ?>"> |
| 96 |
|
| 97 |
<?php if ( isset( $options['filter_items'] ) && $options['filter_items'] ) { ?> |
| 98 |
<div class="sight-portfolio-area-filter"> |
| 99 |
<div class="sight-portfolio-area-filter__title"><?php esc_html_e( 'Categories', 'sight' ); ?></div> |
| 100 |
|
| 101 |
<ul class="sight-portfolio-area-filter__list"> |
| 102 |
|
| 103 |
<li class="sight-portfolio-area-filter__list-item sight-filter-all sight-filter-active"> |
| 104 |
<a href="#" data-filter="*"> |
| 105 |
<?php esc_html_e( 'All', 'sight' ); ?> |
| 106 |
</a> |
| 107 |
</li> |
| 108 |
|
| 109 |
<?php |
| 110 |
$categories = get_terms( |
| 111 |
array( |
| 112 |
'taxonomy' => 'sight-categories', |
| 113 |
'hide_empty' => false, |
| 114 |
'include' => isset( $filter_categories ) && $filter_categories ? $filter_categories : array(), |
| 115 |
) |
| 116 |
); |
| 117 |
|
| 118 |
foreach ( $categories as $category ) { |
| 119 |
?> |
| 120 |
<li class="sight-portfolio-area-filter__list-item"> |
| 121 |
<a href="#" data-filter="<?php echo esc_attr( $category->slug ); ?>"> |
| 122 |
<?php echo esc_html( $category->name ); ?> |
| 123 |
</a> |
| 124 |
</li> |
| 125 |
<?php |
| 126 |
} |
| 127 |
?> |
| 128 |
</ul> |
| 129 |
</div> |
| 130 |
<?php } ?> |
| 131 |
|
| 132 |
<div class="sight-portfolio-area__outer"> |
| 133 |
<div class="sight-portfolio-area__main" <?php sight_portfolio_area_main_attrs( $attributes, $options ); ?>> |
| 134 |
<?php |
| 135 |
// Start the Loop. |
| 136 |
while ( $portfolio_list->have_posts() ) { |
| 137 |
$portfolio_list->the_post(); |
| 138 |
|
| 139 |
$portfolio_entry = new Sight_Entry( $attributes, $options ); |
| 140 |
|
| 141 |
// Init portfolio entry. |
| 142 |
$portfolio_entry->init(); |
| 143 |
|
| 144 |
// Get item project. |
| 145 |
require apply_filters( 'sight_portfolio_item_path', SIGHT_PATH . 'render/handler/portfolio-entry.php', $attributes, $options, $portfolio_entry ); |
| 146 |
} |
| 147 |
?> |
| 148 |
</div> |
| 149 |
</div> |
| 150 |
</div> |
| 151 |
<?php |
| 152 |
} else { |
| 153 |
require SIGHT_PATH . 'render/handler/post-area-none.php'; |
| 154 |
} |
| 155 |
|
| 156 |
wp_reset_postdata(); |
| 157 |
|