Skip to content

Instantly share code, notes, and snippets.

@genesis16
Created December 20, 2021 04:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save genesis16/2acac0fded7015da6ff82b7483e0e828 to your computer and use it in GitHub Desktop.
Save genesis16/2acac0fded7015da6ff82b7483e0e828 to your computer and use it in GitHub Desktop.
<?php
/**
* The template for displaying the Event Index
*
* @package PSN WordPress Theme
* @version 1.0
*/
// Exit if accessed directly.
if (!defined('ABSPATH')) {
exit;
}
get_header();
?>
<?php //nectar_page_header(get_option('page_for_posts')); ?>
<div class="container-wrap">
<div class="container main-content">
<div class="row">
<form action="<?php echo site_url() ?>/wp-admin/admin-ajax.php" method="POST" id="filter">
<div class="col span_4">
<input type="text" class="search-field" placeholder="Search for relevant events here..." value="<?php echo $_REQUEST['search'];?>" name="search" title="Search for:" >
</div>
<?php
$category_posts = get_posts( array( 'post_type' => 'category', 'post_status' => 'publish', 'numberposts' => 30) );
if ($category_posts) :
echo '<div class="col span_2">';
echo '<select name="categoryfilter" class="select2_dropdown"><option value="">Select community...</option>';
foreach( $category_posts as $post ):
if(isset($_REQUEST['categoryfilter']) && $_REQUEST['categoryfilter'] != "" && $_REQUEST['categoryfilter'] == get_the_ID()){
echo '<option value="' . get_the_ID() . '" selected >' . get_the_title() . '</option>'; // ID of the category as an option value
}else{
echo '<option value="' . get_the_ID() . '">' . get_the_title() . '</option>'; // ID of the category as an option value
}
endforeach;
echo '</select>';
echo '</div>';
wp_reset_postdata();
endif;
if ($country_field = get_field_object('country')) :
echo '<div class="col span_2">';
echo '<select name="countryfilter" class="select2_dropdown"><option value="">Select region...</option>';
foreach ($country_field['choices'] as $key => $value) :
if(isset($_REQUEST['countryfilter']) && $_REQUEST['countryfilter'] != "" && $_REQUEST['countryfilter'] == $key ){
echo '<option value="' . $key . '" selected >' . $value . '</option>'; // ID of the category as an option value
}else{
echo '<option value="' . $key . '">' . $value . '</option>'; // ID of the category as an option value
}
endforeach;
echo '</select>';
echo '</div>';
endif;
// if ($label_field = get_field_object('label_event')) :
// echo '<div class="col span_2">';
// echo '<select name="labelfilter"><option value="">Select type...</option>';
// foreach ($label_field['choices'] as $key => $value) :
// echo '<option value="' . $key . '">' . $value . '</option>'; // ID of the category as an option value
// endforeach;
// echo '</select>';
// echo '</div>';
// elseif
if ($label_field = get_field_object('label_event')) :
echo '<div class="col span_2">';
echo '<select name="labelfilter" class="select2_dropdown"><option value="">Select type...</option>';
foreach ($label_field['choices'] as $key => $value) :
if(isset($_REQUEST['labelfilter']) && $_REQUEST['labelfilter'] != "" && $_REQUEST['labelfilter'] == $key ){
echo '<option value="' . $key . '" selected >' . $value . '</option>'; // ID of the category as an option value
}else{
echo '<option value="' . $key . '">' . $value . '</option>';
}
// ID of the category as an option value
endforeach;
echo '</select>';
echo '</div>';
else :
echo '<div class="col span_2">';
echo '<select name="labelfilter" class="select2_dropdown"><option value="">Select type...</option>';
// foreach ($label_field['choices'] as $key => $value) :
echo '<option value="Showcase">Showcase</option>'; // ID of the category as an option value
echo '<option value="Roadshow">Roadshow</option>'; // ID of the category as an option value
echo '<option value="Virtual">Virtual</option>'; // ID of the category as an option value
echo '<option value="Webinar">Webinar</option>'; // ID of the category as an option valur
// endforeach;
echo '</select>';
echo '</div>';
endif; ?>
<?php echo '<div class="col span_2">'; ?>
<input class="nectar-button regular regular-button" style="line-height: 11px;" type="submit" value="Filter">
<input type="hidden" name="action" value="myfilter">
<input type="hidden" name="post_type" value="event">
<?php echo '</div>'; ?>
</form>
<div id="response"></div>
</div><!-- Row End -->
<!-- script -->
<script>
jQuery(function($) {
// Filter Insights
$('#filter').submit(function() {
history.pushState('', 'title', '');
$(".regular-button").addClass('process-btn');
var filter = $('#filter');
$.ajaxSetup({cache: false});
$.ajax({
url: filter.attr('action'),
data: filter.serialize(), // form data
type: filter.attr('method'), // POST
beforeSend: function(xhr) {
filter.find('button').text('Processing...'); // changing the button label
},
success: function(data) {
filter.find('button').text('Submit'); // changing the button label back
$(".regular-button").removeClass('process-btn');
$('#filter-container').empty(); // Remove existing data
$('#filter-container').html(data); // insert data
history.pushState('', 'title', '?' + $('#filter').serialize());
//history.pushState({}, null, newUrl);
}
});
return false;
});
// Pagination
// we will remove the button and load its new copy with AJAX, that's why $('body').on()
/*
* Load More
*/
$('body').on('click', '#psn_loadmore', function() {
var country = jQuery('#filter').find('select[name="countryfilter"]').val();
var postType = jQuery('#filter').find('input[name="post_type"]').val();
var category = jQuery('#filter').find('select[name="categoryfilter"]').val();
// var readTime = jQuery('#filter').find('select[name="readtimefilter"]').val();
var label = jQuery('#filter').find('select[name="labelfilter"]').val();
$.ajax({
url: psn_loadmore_params.ajaxurl, // AJAX handler
data: {
'action': 'loadmore', // the parameter for admin-ajax.php
'query': psn_loadmore_params.posts, // loop parameters passed by wp_localize_script()
'page': psn_loadmore_params.current_page, // current page
'first_page': psn_loadmore_params.first_page,
'countryfilter': country,
'post_type':postType,
'categoryfilter': category,
'labelfilter' : label
},
type: 'POST',
beforeSend: function(xhr) {
$('#psn_loadmore').text('Loading...'); // some type of preloader
},
success: function(data) {
$('#filter-container').append(data);
//$('#psn_loadmore').remove();
//$('#psn_pagination').before(data).remove();
$('#psn_loadmore').text('More Events'); // some type of preloader
psn_loadmore_params.current_page++;
}
});
return false;
});
});
</script>
<style>
@media only screen and (min-width: 690px){
.post-header{
max-height: 81px;
min-height: 80px;
overflow: hidden;
}
}
@media only screen and (max-width: 1300px) and (min-width: 1024px){
.post-header {
max-height: 90px;
min-height: auto;
overflow: hidden;
}
}
</style>
<!-- Script End -->
<div class="row">
<div class="post-area-listing">
<?php
$blog_type = 'std-blog-sidebar';
$masonry_class = $masonry_style = $masonry_style_parsed = $standard_style_parsed = $infinite_scroll_class = null;
$load_in_animation = 'none';
$blog_standard_type = 'classic';
$enable_ss = 'false';
$auto_masonry_spacing = '4px';
$remove_post_date = '0';
$remove_post_author = '0';
$remove_post_comment_number = '0';
$remove_post_nectar_love = '0';
// Enqueue masonry script if selected.
if (
$blog_type === 'masonry-blog-sidebar' ||
$blog_type === 'masonry-blog-fullwidth' ||
$blog_type === 'masonry-blog-full-screen-width'
) {
$masonry_class = 'masonry';
}
$blog_masonry_style = 'classic';
$infinite_scroll_class = ' infinite_scroll';
// Store masonry style.
if ($masonry_class !== null) {
$masonry_style = 'classic';
$masonry_style_parsed = str_replace('_', '-', $masonry_style);
} else {
$standard_style_parsed = str_replace('_', '-', $blog_standard_type);
}
$std_minimal_class = '';
if ($blog_standard_type == 'minimal' && $blog_type === 'std-blog-fullwidth') {
$std_minimal_class = 'standard-minimal full-width-content';
} elseif ($blog_standard_type == 'minimal' && $blog_type === 'std-blog-sidebar') {
$std_minimal_class = 'standard-minimal';
}
if ($masonry_style === null && $blog_standard_type === 'featured_img_left') {
$std_minimal_class = 'featured_img_left';
}
if ($blog_type === 'std-blog-sidebar' || $blog_type === 'masonry-blog-sidebar') {
echo '<div class="post-area col ' . $std_minimal_class . ' span_9 ' . esc_attr($masonry_class) . ' ' . esc_attr($masonry_style) . ' ' . $infinite_scroll_class . '" data-ams="' . esc_attr($auto_masonry_spacing) . '" data-remove-post-date="' . esc_attr($remove_post_date) . '" data-remove-post-author="' . esc_attr($remove_post_author) . '" data-remove-post-comment-number="' . esc_attr($remove_post_comment_number) . '" data-remove-post-nectar-love="' . esc_attr($remove_post_nectar_love) . '"> <div id="filter-container" class="posts-container" data-load-animation="' . esc_attr($load_in_animation) . '">'; // WPCS: XSS ok.
} else {
if (
$blog_type === 'masonry-blog-full-screen-width' && $blog_masonry_style === 'auto_meta_overlaid_spaced' ||
$blog_type === 'masonry-blog-full-screen-width' && $blog_masonry_style === 'meta_overlaid'
) {
echo '<div class="full-width-content blog-fullwidth-wrap meta-overlaid">';
} elseif ($blog_type === 'masonry-blog-full-screen-width') {
echo '<div class="full-width-content blog-fullwidth-wrap">';
}
echo '<div class="post-area col ' . $std_minimal_class . ' span_12 col_last ' . esc_attr($masonry_class) . ' ' . esc_attr($masonry_style) . ' ' . $infinite_scroll_class . '" data-ams="' . esc_attr($auto_masonry_spacing) . '" data-remove-post-date="' . esc_attr($remove_post_date) . '" data-remove-post-author="' . esc_attr($remove_post_author) . '" data-remove-post-comment-number="' . esc_attr($remove_post_comment_number) . '" data-remove-post-nectar-love="' . esc_attr($remove_post_nectar_love) . '"> <div class="insights-container" id="filter-container" data-load-animation="' . esc_attr($load_in_animation) . '">'; // WPCS: XSS ok.
}
add_filter('wp_get_attachment_image_attributes', 'nectar_remove_lazy_load_functionality');
$args = array();
// if ( isset($_REQUEST['post_type']) ) {
// $args = array(
// 'post_type' => $_REQUEST['post_type'],
// 'post_status' => 'publish',
// );
// } else {
// $args = array(
// 'post_type' => 'insight',
// 'post_status' => 'publish',
// );
// }
$args = array(
'post_type' => 'event',
'post_status' => 'publish',
);
// Search by Keyword
if ( isset($_REQUEST['search']) && !empty($_REQUEST['search'])) {
$args['s'] = $_REQUEST['search'];
}
// create $args['meta_query'] array if one of the following fields is filled
if (isset($_REQUEST['readtimefilter']) || isset($_REQUEST['labelfilter']))
$args['meta_query'] = array('relation' => 'AND'); // AND means that all conditions of meta_query should be true
//if country is set
if( isset($_REQUEST['post_type']) && $_REQUEST['post_type'] === "supplier"){
if (isset($_REQUEST['countryfilter']) && $_REQUEST['countryfilter'] != "")
$args['meta_query'][] = array(
'key' => 'location_country',
'value' => $_REQUEST['countryfilter'],
);
} else{
if (isset($_REQUEST['countryfilter']) && $_REQUEST['countryfilter'] != ""){
$args['meta_query'][] = array(
'relation' => 'OR',
'country'=>array(
'key' => 'country',
'value' => $_REQUEST['countryfilter'],
'compare' => 'LIKE',
),
);
}
}
if (isset($_REQUEST['categoryfilter']) && $_REQUEST['categoryfilter'] != "")
$args['meta_query'][] = array(
'key' => 'categories',
'value' => $_REQUEST['categoryfilter'],
'compare' => 'LIKE',
);
//$today = date("d/m/y");
if (isset($_REQUEST['post_type']) && $_REQUEST['post_type'] === "event"){
$args['meta_key'] = 'start_date';
$args['orderby'] = 'meta_value';
$args['order'] = 'ASC';
$today = date('Y-m-d H:i:s',time());
$args['meta_query'][] = array(
'key' => 'start_date',
'value' => $today,
'compare' => '>=',
'type' => 'DATE',
);
// Label
if (isset($_REQUEST['labelfilter']) && $_REQUEST['labelfilter'] != "")
$args['meta_query'][] = array(
'key' => 'label_event',
'value' => $_REQUEST['labelfilter'],
);
} else {
$args['meta_key'] = 'start_date';
$args['orderby'] = 'meta_value';
$args['order'] = 'ASC';
$today = date('Y-m-d H:i:s',time());
$args['meta_query'][] = array(
'key' => 'start_date',
'value' => $today,
'compare' => '>=',
'type' => 'DATE',
);
if (isset($_REQUEST['labelfilter']) && $_REQUEST['labelfilter'] != "")
$args['meta_query'][] = array(
'key' => 'label',
'value' => $_REQUEST['labelfilter'],
);
}
if (!is_user_logged_in() ) {
$args['meta_query'][] = array(
'key' => 'is_external',
'value' => 1,
);
}
// echo "<pre>"; print_r( $args ); exit;
echo "<div class='list-data-section'>";
query_posts($args);
//echo $GLOBALS['wp_query']->request;
// Main post loop.
if (have_posts()) :
while (have_posts()) :
the_post();
if( get_post_status()=='private' ) continue;
$nectar_post_format = get_post_format();
if (
get_post_format() === 'image' ||
get_post_format() === 'aside' ||
get_post_format() === 'status'
) {
$nectar_post_format = false;
}
?>
<article class="common-listing-data">
<div class="inner-wrap animated">
<div class="post-content">
<div class="content-inner">
<a class="entire-meta-link" href="<?php the_permalink(); ?>"></a>
<?php
$blog_lazy_load =1;
// Featured image.
$image_attrs = array(
'title' => '',
'sizes' => '(min-width: 1600px) 20vw, (min-width: 1300px) 25vw, (min-width: 1000px) 33.3vw, (min-width: 690px) 50vw, 100vw',
);
if( has_post_thumbnail() ) {
// Lazy load.
if( !empty($blog_lazy_load) ) {
// src.
$img_src = wp_get_attachment_image_src( get_post_thumbnail_id(), 'large');
// srcset.
$img_srcset = '';
if (function_exists('wp_get_attachment_image_srcset')) {
$img_srcset = wp_get_attachment_image_srcset(get_post_thumbnail_id(), 'large');
}
// alt.
$alt_tag = get_post_meta( get_post_thumbnail_id(), '_wp_attachment_image_alt', true );
// dimensions.
$img_meta = wp_get_attachment_metadata(get_post_thumbnail_id());
$width = ( !empty($img_meta['width']) ) ? $img_meta['width'] : '100';
$height = ( !empty($img_meta['height']) ) ? $img_meta['height'] : '100';
echo '<a href="' . esc_url( get_permalink() ) . '"><span class="post-featured-img">';
if( 'video' === $nectar_post_format || 'audio' === $nectar_post_format ) {
get_template_part( 'includes/partials/blog/media/play-button' );
}
echo '<span class="psn-label">'.get_field('label_event').'</span><img class="nectar-lazy skip-lazy wp-post-image" alt="'.esc_attr($alt_tag).'" height="'.esc_attr($height).'" width="'.esc_attr($width).'" src="'.esc_attr($img_src[0]).'" data-nectar-img-srcset="'.esc_attr($img_srcset).'" sizes="'.esc_attr($image_attrs['sizes']).'" />';
echo '</span></a>';
} else {
echo '<a href="' . esc_url( get_permalink() ) . '"><span class="post-featured-img psn-grid-img">';
if( 'video' === $nectar_post_format || 'audio' === $nectar_post_format ) {
get_template_part( 'includes/partials/blog/media/play-button' );
}
if(get_the_post_thumbnail( $post->ID, 'psn-thumb', $image_attrs )){
if( get_field('label_event')) echo '<span class="psn-label">' . get_field('label_event') . '</span>';
echo get_the_post_thumbnail( $post->ID, 'psn-thumb', $image_attrs ) . '</span></a>';
} else {
if( get_field('label_event')) echo '<span class="psn-label">' . get_field('label_event') . '</span>';
echo '<img width="1024" height="683" src="' . get_stylesheet_directory_uri() . '/assets/placeholder.jpg' . '" class="attachment-large size-large skip-lazy wp-post-image" alt="" title=" Placeholder image" >' . '</span></a>';
}
}
} else {
if(get_post_type() === "insight" || get_post_type() === "psntv" || get_post_type() === "supplier" || get_post_type() === "event" ){
if( get_field('label_event')) echo '<span class="psn-label">' . get_field('label_event') . '</span>';
echo '<img width="1024" height="683" src="' . get_stylesheet_directory_uri() . '/assets/placeholder.jpg' . '" class="attachment-large size-large skip-lazy wp-post-image" alt="" title=" Placeholder image" >' . '</span></a>';
}
}
?>
<?php
// Output Durations and Location.
echo '<span class="meta-category">';
if(get_field('start_date')){
$date_string = get_field('start_date');
$timestamp = strtotime( (str_replace('/', '-', $date_string ) ));
echo $new_date = date('j M Y', $timestamp);
// Create DateTime object from value (formats must match).
// $date = new DateTime($date_string);
// echo $date->format('j M Y');
}
$country_list =get_field('country');
foreach($country_list as $key_country => $val_country){
if( !empty($val_country)): ?>
<span class="psn-flag" style="background-image:url(<?php echo get_stylesheet_directory_uri() . '/assets/country/' . $val_country . '.svg'; ?>)" >
<?php //echo strtoupper(get_field('country')); ?>
</span>
<?php endif;
}
echo '</span>';
?>
<div class="article-content-wrap">
<div class="post-header">
<h3 class="title"><a href="<?php the_permalink(); ?>"> <?php the_title(); ?></a></h3>
</div>
<?php
// Excerpt.
echo '<div class="excerpt">';
if(get_field('description')) echo wp_trim_words(get_field('description'), 20) ;
echo '</div>';
// Bottom author link & date.
?>
</div><!--article-content-wrap-->
</div><!--/content-inner-->
</div><!--/post-content-->
</div><!--/inner-wrap-->
</article>
<?php
endwhile;
wp_reset_postdata();
//echo "test data12344";
//exit;
endif;
?>
</div>
</div>
<!--/posts container-->
<?php //nectar_pagination();
?>
<?php //psn_paginator(get_pagenum_link()) ?>
<!-- <div class="button solid_color" style="text-align: center; width:100%;">
<a href="#" class="primary-color button regular" id="load-more">Load More</a>
</div> -->
</div>
</div>
<!--/post-area-->
<?php
if ($blog_type === 'masonry-blog-full-screen-width') {
echo '</div>';
}
?>
<?php if ($blog_type === 'std-blog-sidebar11' || $blog_type === 'masonry-blog-sidebar11') { ?>
<div id="sidebar" data-nectar-ss="<?php echo esc_attr($enable_ss); ?>" class="col span_3 col_last">
<?php get_sidebar(); ?>
</div>
<!--/span_3-->
<?php } ?>
</div>
<!--/row-->
</div>
<!--/container-->
</div>
<!--/container-wrap-->
<?php get_footer(); ?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment