Skip to content

Instantly share code, notes, and snippets.

/travel-log-child
Created Feb 22, 2018

Embed
What would you like to do?
/**
* Front page post filter section content.
*
* @since 1.0.0
*/
function travel_log_front_page_post_filter_content() {
$enabled = travel_log_get_theme_option( 'post_filter_enable' );
$title = travel_log_get_theme_option( 'post_filter_title' );
$sub_title = travel_log_get_theme_option( 'post_filter_sub_title' );
$categories = travel_log_get_theme_option( 'post_filter_category' );
$content_type = travel_log_get_theme_option( 'post_filter_content_type' );
if ( class_exists( 'WP_Travel' ) ) :
if ( 'trip-types' === $content_type ) :
$categories = travel_log_get_theme_option( 'post_filter_category_trip_type' );
elseif ( 'trip-location' === $content_type ) :
$categories = travel_log_get_theme_option( 'post_filter_category_trip_location' );
endif;
endif;
if ( ! $enabled ) {
return;
}
?>
<section id="tab-tours" class="tab-tours">
<div class="container">
<div class="row">
<div class="col-sm-12">
<h2 class="section-title"><?php echo esc_html( $title ); ?></h2>
<div class="title-tagline">
<p><?php echo esc_html( $sub_title ); ?></p>
</div>
</div>
</div>
<div class="row">
<div class="col-sm-12">
<ul id="filters" class="post-filter-controls">
<?php
if ( ! empty( $categories ) ) :
foreach ( $categories as $category ) :
if ( 'trip-types' === $content_type && class_exists( 'WP_Travel' ) ) {
$term = get_term( (int) $category, 'itinerary_types' );
$term_id = $term->term_taxonomy_id;
} elseif ( 'trip-location' === $content_type && class_exists( 'WP_Travel' ) ) {
$term = get_term( (int) $category, 'travel_locations' );
$term_id = $term->term_taxonomy_id;
} else {
$term = get_term( (int) $category, 'category' );
$term_id = $term->term_id;
}
?>
<li class="filter" data-filter=".<?php echo absint( $term_id ); ?>"><span><?php echo esc_html( $term->name ); ?></span></li>
<?php
endforeach;
endif;
?>
</ul>
<div class="filtr-container" id="tourlist">
<ul class="wp-travel-itinerary-list" >
<?php
if ( ! empty( $categories ) ) {
if ( 'trip-types' === $content_type && class_exists( 'WP_Travel' ) ) {
$args = array(
'post_type' => travel_log_wp_travel_support_get_post_type(),
'tax_query' => array(
array(
'taxonomy' => 'itinerary_types',
'field' => 'id',
'terms' => $categories,
),
),
);
} elseif ( 'trip-location' === $content_type && class_exists( 'WP_Travel' ) ) {
$args = array(
'post_type' => travel_log_wp_travel_support_get_post_type(),
'tax_query' => array(
array(
'taxonomy' => 'travel_locations',
'field' => 'id',
'terms' => $categories,
),
),
);
} else {
$args['cat'] = $categories;
}
} else {
if ( 'trip-types' === $content_type || 'trip-location' === $content_type && class_exists( 'WP_Travel' ) ) {
$args['post_type'] = travel_log_wp_travel_support_get_post_type();
}
}
$args['posts_per_page'] = apply_filters( 'travel_log_posts_filter_posts_limit', 9 );
$slider_posts = new WP_Query( $args );
if ( $slider_posts->have_posts() ) :
while ( $slider_posts->have_posts() ) :
$slider_posts->the_post();
$category_detail = get_the_category( get_the_ID() );
if ( class_exists( 'WP_Travel' ) ) :
if ( 'trip-types' == $content_type ) :
$category_detail = get_the_terms( get_the_ID(), 'itinerary_types' );
elseif ( 'trip-location' == $content_type ) :
$category_detail = get_the_terms( get_the_ID(), 'travel_locations' );
endif;
endif;
$category_ids = !empty( $category_detail ) ? wp_list_pluck( $category_detail, 'term_id' ) : '';
$category_ids = ! empty( $category_ids ) ? implode( ' ', $category_ids ) : '';
echo '<div class="col-md-4 col-sm-6 col-xs-12 filtr-item ' . $category_ids . '">';
$args = array(
'thumbnail_size' => 'medium',
);
if ( class_exists( 'WP_Travel' ) ) :
if ( 'trip-types' === $content_type || 'trip-location' === $content_type ) :
get_template_part( 'template-parts/wp-travel/itinerary', 'item' );
else :
// Load Content Template.
travel_log_trip_content( $args );
endif;
else :
// Load Content Template.
travel_log_trip_content( $args );
endif;
echo '</div>';
endwhile;
wp_reset_postdata();
endif;
?>
</ul>
</div>
</div>
</div>
</div>
</section>
<?php
}
function travel_log_child_custom_trips_filter_js(){
?>
<script type="text/javascript">
jQuery(function($) {
$(window).load(function() {
jQuery('#filters > .filter:nth-of-type(1)').trigger('click');
});
} );
</script>
<?php
}
add_action('wp_footer', 'travel_log_child_custom_trips_filter_js');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.