function mtphr_gallery_archive_display($atts, $content = null) { // Set the defaults $defaults = array('posts_per_page' => 6, 'columns' => 3, 'order' => 'DESC', 'orderby' => 'menu_order', 'categories' => false, 'tags' => false, 'operator' => 'IN', 'excerpt_length' => 140, 'excerpt_more' => '…', 'assets' => 'thumbnail,like,title,excerpt', 'responsive' => false); $defaults = apply_filters('mtphr_gallery_archive_default_args', $defaults); $args = shortcode_atts($defaults, $atts); extract($args); // Set the responsiveness of the grid $row = apply_filters('mtphr_galleries_responsive_grid', $responsive); $row_class = $row ? 'mtphr-galleries-row-responsive' : 'mtphr-galleries-row'; // Filter the container $container = apply_filters('mtphr_gallery_container', 'article'); // Set the span $span = intval(12 / intval($columns)); // Create an array of the order $asset_order = explode(',', $assets); $page = get_query_var('paged') ? get_query_var('paged') : 1; $args = array('post_type' => 'mtphr_gallery', 'order' => sanitize_text_field($order), 'orderby' => sanitize_text_field($orderby), 'paged' => $page, 'posts_per_page' => intval($posts_per_page)); // Check for query var filters if (isset($_GET['category'])) { $categories = $_GET['category']; } if (isset($_GET['tag'])) { $tags = $_GET['tag']; } if ($categories || $tags) { $args['tax_query'] = array(); } if ($categories) { $category_array = explode(',', $categories); $args['tax_query'][] = array('taxonomy' => 'mtphr_gallery_category', 'field' => 'slug', 'terms' => $category_array, 'operator' => $operator); } if ($tags) { $tag_array = explode(',', $tags); $args['tax_query'][] = array('taxonomy' => 'mtphr_gallery_tag', 'field' => 'slug', 'terms' => $tag_array, 'operator' => $operator); } // Save the original query & create a new one global $wp_query; $original_query = $wp_query; $wp_query = null; $wp_query = new WP_Query(); $wp_query->query($args); ?> <?php ob_start(); ?> <div class="mtphr-galleries-archive"> <?php if ($wp_query->have_posts()) { while ($wp_query->have_posts()) { $wp_query->the_post(); ?> <?php // Get the count $count = $wp_query->current_post; if ($count % intval($columns) == 0) { echo '<div class="' . $row_class . '">'; } ?> <div class="mtphr-galleries-grid<?php echo $span; ?> "> <?php do_action('mtphr_gallery_before'); ?> <<?php echo $container; ?> id="post-<?php the_id(); ?> " <?php post_class('mtphr-clearfix'); ?> > <?php do_action('mtphr_gallery_top'); ?> <?php $permalink = $categories ? esc_url(add_query_arg(array('taxonomy' => 'mtphr_gallery_category', 'terms' => $categories), get_permalink())) : esc_url(remove_query_arg(array('taxonomy', 'terms'), get_permalink())); foreach ($asset_order as $asset) { switch (trim($asset)) { case 'thumbnail': // Display the gallery thumb if ($thumbnail = get_mtphr_gallery_thumbnail()) { echo apply_filters('mtphr_gallery_thumbnail', $thumbnail, $permalink); } break; case 'like': echo get_mtphr_gallery_likes(); break; case 'title': // Display the gallery title $title = '<h2 class="mtphr-gallery-title"><a href="' . $permalink . '" title="' . sprintf(esc_attr__('Permalink to %s', 'mtphr-galleries'), the_title_attribute('echo=0')) . '" rel="bookmark">' . get_the_title() . '</a></h2>'; echo apply_filters('mtphr_gallery_archive_title', $title); break; case 'excerpt': if ($excerpt_length > 0) { $excerpt = wp_html_excerpt(get_the_excerpt(), intval($excerpt_length)); $links = array(); preg_match('/{(.*?)\\}/s', $excerpt_more, $links); if (isset($links[0])) { $more_link = '<a href="' . $permalink . '">' . $links[1] . '</a>'; $more = preg_replace('/{(.*?)\\}/s', $more_link, $excerpt_more); $excerpt .= $more; } // Display the member excerpt echo '<p class="mtphr-gallery-excerpt">' . apply_filters('mtphr_gallery_excerpt', $excerpt, $excerpt_length, $excerpt_more) . '</p>'; } break; } } ?> <?php do_action('mtphr_gallery_bottom'); ?> </<?php echo $container; ?> ><!-- #post-<?php the_ID(); ?> --> <?php do_action('mtphr_gallery_after'); ?> </div> <?php // Get the count $count = $count + 1; if ($count % intval($columns) == 0 || $count == $wp_query->post_count) { echo '</div>'; } ?> <?php } } else { } ?> <?php if ($wp_query->max_num_pages > 1) { ?> <?php ob_start(); ?> <nav class="mtphr-galleries-content-nav clearfix"> <?php if ($prev = get_previous_posts_link(__('Newer', 'mtphr-galleries'))) { ?> <div class="mtphr-galleries-nav-next"><?php echo $prev; ?> </div> <?php } ?> <?php if ($next = get_next_posts_link(__('Older', 'mtphr-galleries'))) { ?> <div class="mtphr-galleries-nav-previous"><?php echo $next; ?> </div> <?php } ?> </nav> <?php echo apply_filters('mtphr_galleries_archive_navigation', ob_get_clean()); ?> <?php } ?> <?php $wp_query = null; $wp_query = $original_query; wp_reset_postdata(); ?> </div><!-- .mtphr-gallery-archive --> <?php // Return the output return ob_get_clean(); }
function get_mtphr_gallery($post_id = false, $args = false, $class = '') { // Get the post id $post_id = $post_id ? $post_id : get_the_id(); // Get all the custom data $custom_fields = get_post_custom($post_id); $meta_data = array(); foreach ($custom_fields as $key => $value) { $meta_data[$key] = maybe_unserialize($value[0]); } // Manually set the layout $meta_data['_mtphr_gallery_slider_layout'] = array('navigation', 'gallery'); // Override meta data with supplied attributes if (is_array($args)) { foreach ($args as $key => $value) { $meta_data["_mtphr_gallery_{$key}"] = $value; } } // Extract the metadata array into variables extract($meta_data); // Create the gallery $gallery_id = 'mtphr-gallery-' . $post_id; $html = '<div id="' . $gallery_id . '" class="mtphr-gallery ' . sanitize_html_class($class) . '">'; // Set the layout if (!is_array($_mtphr_gallery_slider_layout)) { $_mtphr_gallery_slider_layout = explode(',', $_mtphr_gallery_slider_layout); } foreach ($_mtphr_gallery_slider_layout as $asset) { switch ($asset) { case 'like': $html .= get_mtphr_gallery_likes(); break; case 'navigation': if (isset($_mtphr_gallery_slider_control_nav) && $_mtphr_gallery_slider_control_nav) { $html .= get_mtphr_galleries_navigation($post_id); } break; case 'gallery': $html .= '<div class="mtphr-gallery-wrapper">'; $html .= apply_filters('mtphr_gallery', get_mtphr_gallery_resources($post_id), $post_id); if (isset($_mtphr_gallery_slider_directional_nav) && $_mtphr_gallery_slider_directional_nav) { $html .= '<a href="#" class="mtphr-gallery-nav-prev" rel="nofollow">' . apply_filters('mtphr_gallery_navigation_previous', __('Previous', 'mtphr-galleries')) . '</a>'; $html .= '<a href="#" class="mtphr-gallery-nav-next" rel="nofollow">' . apply_filters('mtphr_gallery_navigation_next', __('Next', 'mtphr-galleries')) . '</a>'; } $html .= '</div>'; break; } } $html .= '</div>'; // Add an after action ob_start(); do_action('mtphr_gallery_slider_after', $gallery_id, $meta_data); $html .= ob_get_clean(); // Add to the gallery scripts to display in the footer global $mtphr_galleries_scripts; $rotate = 0; $pause = 0; $nav_autohide = 0; $nav_reverse = 0; if (isset($_mtphr_gallery_slider_auto_rotate)) { $rotate = $_mtphr_gallery_slider_auto_rotate ? 1 : 0; } if (isset($_mtphr_gallery_slider_pause)) { $pause = $_mtphr_gallery_slider_pause ? 1 : 0; } if (isset($_mtphr_gallery_slider_directional_nav_reverse)) { $nav_reverse = $_mtphr_gallery_slider_directional_nav_reverse ? 1 : 0; } $mtphr_galleries_scripts[] = array('id' => $gallery_id, 'rotate_type' => $_mtphr_gallery_slider_type, 'auto_rotate' => $rotate, 'rotate_delay' => intval($_mtphr_gallery_slider_delay), 'rotate_pause' => $pause, 'rotate_speed' => intval($_mtphr_gallery_slider_speed), 'rotate_ease' => $_mtphr_gallery_slider_ease, 'nav_reverse' => $nav_reverse); // Return the gallery return $html; }
/** * Return the gallery * * @since 2.0.13 */ function get_mtphr_gallery($post_id = false, $width = false, $height = false, $args = false, $class = '') { $settings = mtphr_galleries_settings(); // Get the post id $post_id = $post_id ? $post_id : get_the_id(); // Get all the custom data $custom_fields = get_post_custom($post_id); $meta_data = array(); foreach ($custom_fields as $key => $value) { $meta_data[$key] = maybe_unserialize($value[0]); } // Manually set the layout $meta_data['_mtphr_gallery_slider_layout'] = array('navigation', 'gallery'); // Override meta data with supplied attributes if (is_array($args)) { foreach ($args as $key => $value) { $meta_data["_mtphr_gallery_{$key}"] = $value; } } // Extract the metadata array into variables extract($meta_data); $control_nav = $settings['global_slider_settings'] == 'on' ? $settings['slider_control_nav'] == 'on' : isset($_mtphr_gallery_slider_control_nav) && $_mtphr_gallery_slider_control_nav; // Create the gallery $gallery_id = 'mtphr-gallery-' . $post_id; $html = '<div id="' . $gallery_id . '" class="mtphr-gallery ' . sanitize_html_class($class) . '">'; ob_start(); do_action('mtphr_gallery_slider_top', $post_id, $meta_data); $html .= ob_get_clean(); // Set the layout if (!is_array($_mtphr_gallery_slider_layout)) { $_mtphr_gallery_slider_layout = explode(',', $_mtphr_gallery_slider_layout); } foreach ($_mtphr_gallery_slider_layout as $asset) { switch ($asset) { case 'like': if ($control_nav) { $html .= get_mtphr_gallery_likes(); } break; case 'navigation': if ($control_nav) { $html .= get_mtphr_galleries_navigation($post_id); } break; case 'gallery': $html .= '<div class="mtphr-gallery-wrapper">'; // Add an after action ob_start(); do_action('mtphr_gallery_wrapper', $post_id, $meta_data); $html .= ob_get_clean(); $html .= '</div>'; break; } } ob_start(); do_action('mtphr_gallery_slider_bottom', $post_id, $meta_data); $html .= ob_get_clean(); $html .= '</div>'; // Add an after action ob_start(); do_action('mtphr_gallery_slider_after', $gallery_id, $meta_data); $html .= ob_get_clean(); // Add to the gallery scripts to display in the footer global $mtphr_galleries_scripts; if ($settings['global_slider_settings'] == 'on') { $mtphr_galleries_scripts = array('on'); } else { $rotate = 0; $pause = 0; $nav_autohide = 0; $nav_reverse = 0; if (isset($_mtphr_gallery_slider_auto_rotate)) { $rotate = $_mtphr_gallery_slider_auto_rotate ? 1 : 0; } if (isset($_mtphr_gallery_slider_pause)) { $pause = $_mtphr_gallery_slider_pause ? 1 : 0; } if (isset($_mtphr_gallery_slider_directional_nav_reverse)) { $nav_reverse = $_mtphr_gallery_slider_directional_nav_reverse ? 1 : 0; } if (!empty($_mtphr_gallery_slider_type)) { $mtphr_galleries_scripts[] = array('id' => $gallery_id, 'rotate_type' => $_mtphr_gallery_slider_type, 'auto_rotate' => $rotate, 'rotate_delay' => intval($_mtphr_gallery_slider_delay), 'rotate_pause' => $pause, 'rotate_speed' => intval($_mtphr_gallery_slider_speed), 'rotate_ease' => $_mtphr_gallery_slider_ease, 'nav_reverse' => $nav_reverse); } } // Return the gallery return $html; }