function barcelona_category_pre_posts($query) { if ($query->is_main_query() && is_category() && !is_admin()) { $barcelona_cat = get_queried_object(); $barcelona_fp_query = barcelona_get_featured_posts_query($barcelona_cat->term_id, 'category'); $barcelona_post_ids = array(); if ($barcelona_fp_query && $barcelona_fp_query->have_posts()) { while ($barcelona_fp_query->have_posts()) { $barcelona_fp_query->the_post(); $barcelona_post_ids[] = get_the_ID(); } } $query->set('post__not_in', $barcelona_post_ids); } return $query; }
/** * Featured Posts */ function barcelona_featured_posts() { global $barcelona_mod_header; $barcelona_fp_type = 'category'; $barcelona_has_autoplay = false; if (is_page_template('page-modules.php')) { global $post; $barcelona_fp_type = 'page'; $barcelona_q = barcelona_get_featured_posts_query($post->ID, $barcelona_fp_type); $barcelona_has_autoplay = get_post_meta($post->ID, 'barcelona_fp_is_autoplay', true) == 'on'; } else { if (is_category()) { $barcelona_cat_id = get_query_var('cat'); $barcelona_q = barcelona_get_featured_posts_query($barcelona_cat_id, $barcelona_fp_type); $barcelona_has_autoplay = barcelona_get_option('fp_is_autoplay__category_' . $barcelona_cat_id) == 'on'; } } if (!isset($barcelona_q) || !$barcelona_q) { return false; } if ($barcelona_q->have_posts()) { $barcelona_fp_style = $barcelona_q->fp_style; $barcelona_owl_data = array('dots' => 'false', 'items' => 2, 'center' => 'false', 'nav' => 'true', 'rtl' => is_rtl() ? 'true' : 'false', 'breakpoint' => '0:1,992:', 'loop' => 'false', 'slideby' => 2); if ($barcelona_has_autoplay) { $barcelona_owl_data['loop'] = 'true'; $barcelona_owl_data['autoplay'] = 'true'; } if ($barcelona_fp_style == 'a') { $barcelona_owl_data['items'] = $barcelona_owl_data['slideby'] = 1; $barcelona_owl_data['breakpoint'] .= '1'; } else { $barcelona_owl_data['breakpoint'] .= '2'; } ?> <div class="featured-posts fptype-<?php echo sanitize_html_class($barcelona_fp_type); ?> fpstyle-<?php echo sanitize_html_class($barcelona_fp_style); ?> "> <div class="container"> <div class="owl-carousel owl-theme"<?php echo implode(array_map(function ($v, $k) { return ' data-' . sanitize_key($k) . '="' . esc_attr($v) . '"'; }, $barcelona_owl_data, array_keys($barcelona_owl_data))); ?> > <?php $i = 0; while ($barcelona_q->have_posts()) { $barcelona_q->the_post(); $barcelona_h = 2; if ($barcelona_fp_style == 'c' && ($i + 1) % 3 != 0 || $barcelona_fp_style == 'd' && $i % 3 != 0 || $barcelona_fp_style == 'e') { $barcelona_h = 1; } if (($barcelona_fp_style == 'c' && $barcelona_q->post_count % 3 == 1 || $barcelona_fp_style == 'd' && $barcelona_q->post_count % 3 == 2) && $i == $barcelona_q->post_count - 1) { $barcelona_h = 2; } $barcelona_c = $barcelona_fp_style == 'a' ? 1 : 2; $barcelona_thumbnail_url = barcelona_get_thumbnail_url('barcelona-lg'); ?> <?php if (($barcelona_fp_style != 'c' || ($i - 1) % 3 != 0) && ($barcelona_fp_style != 'd' || ($i + 1) % 3 != 0)) { ?> <div class="item fp-col"> <?php } ?> <div id="fpBox<?php echo intval($i + 1); ?> " class="post-summary fp-box fp-box-h<?php echo intval($barcelona_h); ?> fp-box-c<?php echo intval($barcelona_c); ?> " data-bg="<?php echo esc_url($barcelona_thumbnail_url[0]); ?> "> <a href="<?php echo esc_url(get_the_permalink()); ?> " class="fp-inner"> <div class="vm-wrapper"> <div class="vm-middle"> <h2 class="post-title"><?php echo esc_html(get_the_title()); ?> </h2> <ul class="post-meta no-sep"> <li class="post-date"><span class="fa fa-clock-o"></span><?php echo esc_html(get_the_time(BARCELONA_DATE_FORMAT)); ?> </li> </ul> </div> </div> </a> </div> <?php if (!barcelona_is_empty($barcelona_thumbnail_url[0])) { ?> <script>jQuery(document).ready(function($){ $('#fpBox<?php echo intval($i + 1); ?> ').backstretch('<?php echo esc_url($barcelona_thumbnail_url[0]); ?> ', {fade: 400}); });</script> <?php } ?> <?php if (($barcelona_fp_style != 'c' || $i % 3 != 0) && ($barcelona_fp_style != 'd' || ($i - 1) % 3 != 0) || $i == $barcelona_q->post_count - 1) { ?> </div> <?php } ?> <?php $i++; } wp_reset_postdata(); ?> </div> </div> </div><!-- .featured-posts --> <?php if (isset($barcelona_mod_header)) { echo '<div class="container">' . $barcelona_mod_header . '</div>'; } return true; } }