Exemplo n.º 1
0
 /**
  * @param array $args
  * @param array $instance
  */
 function widget($args, $instance)
 {
     if (empty($instance['template'])) {
         return;
     }
     if (is_admin()) {
         return;
     }
     static $depth = 0;
     $depth++;
     if ($depth > 1) {
         // Because of infinite loops, don't render this post loop if its inside another
         $depth--;
         echo $args['before_widget'] . $args['after_widget'];
         return;
     }
     $query_args = $instance;
     //If Widgets Bundle post selector is available and a posts query has been saved using it.
     if (function_exists('siteorigin_widget_post_selector_process_query') && !empty($instance['posts'])) {
         $query_args = siteorigin_widget_post_selector_process_query($instance['posts']);
         $query_args['additional'] = empty($instance['additional']) ? array() : $instance['additional'];
     } else {
         if (!empty($instance['posts'])) {
             $query_args = wp_parse_args($instance['posts'], $query_args);
         }
         switch ($query_args['sticky']) {
             case 'ignore':
                 $query_args['ignore_sticky_posts'] = 1;
                 break;
             case 'only':
                 $query_args['post__in'] = get_option('sticky_posts');
                 break;
             case 'exclude':
                 $query_args['post__not_in'] = get_option('sticky_posts');
                 break;
         }
         unset($query_args['template']);
         unset($query_args['title']);
         unset($query_args['sticky']);
         if (empty($query_args['additional'])) {
             $query_args['additional'] = array();
         }
     }
     $query_args = wp_parse_args($query_args['additional'], $query_args);
     unset($query_args['additional']);
     global $wp_rewrite;
     if ($wp_rewrite->using_permalinks()) {
         if (get_query_var('paged')) {
             // When the widget appears on a sub page.
             $query_args['paged'] = get_query_var('paged');
         } elseif (strpos($_SERVER['REQUEST_URI'], '/page/') !== false) {
             // When the widget appears on the home page.
             preg_match('/\\/page\\/([0-9]+)\\//', $_SERVER['REQUEST_URI'], $matches);
             if (!empty($matches[1])) {
                 $query_args['paged'] = intval($matches[1]);
             } else {
                 $query_args['paged'] = 1;
             }
         } else {
             $query_args['paged'] = 1;
         }
     } else {
         // Get current page number when we're not using permalinks
         $query_args['paged'] = isset($_GET['paged']) ? intval($_GET['paged']) : 1;
     }
     // Exclude the current post to prevent possible infinite loop
     global $siteorigin_panels_current_post;
     if (!empty($siteorigin_panels_current_post)) {
         if (!empty($query_args['post__not_in'])) {
             if (!is_array($query_args['post__not_in'])) {
                 $query_args['post__not_in'] = explode(',', $query_args['post__not_in']);
                 $query_args['post__not_in'] = array_map('intval', $query_args['post__not_in']);
             }
             $query_args['post__not_in'][] = $siteorigin_panels_current_post;
         } else {
             $query_args['post__not_in'] = array($siteorigin_panels_current_post);
         }
     }
     if (!empty($query_args['post__in']) && !is_array($query_args['post__in'])) {
         $query_args['post__in'] = explode(',', $query_args['post__in']);
         $query_args['post__in'] = array_map('intval', $query_args['post__in']);
     }
     // Create the query
     query_posts($query_args);
     echo $args['before_widget'];
     // Filter the title
     $instance['title'] = apply_filters('widget_title', $instance['title'], $instance, $this->id_base);
     if (!empty($instance['title'])) {
         echo $args['before_title'] . $instance['title'] . $args['after_title'];
     }
     global $more;
     $old_more = $more;
     $more = empty($instance['more']);
     self::$rendering_loop = true;
     if (strpos('/' . $instance['template'], '/content') !== false) {
         while (have_posts()) {
             the_post();
             locate_template($instance['template'], true, false);
         }
     } else {
         locate_template($instance['template'], true, false);
     }
     self::$rendering_loop = false;
     echo $args['after_widget'];
     // Reset everything
     wp_reset_query();
     $depth--;
 }
    /**
     * Display navigation to next/previous pages when applicable
     *
     * @since vantage 1.0
     */
    function vantage_content_nav($nav_id)
    {
        $jetpack_infinite_scroll_active = class_exists('Jetpack') && Jetpack::is_module_active('infinite-scroll');
        //Check if we're in the Page Builder Post Loop widget.
        $is_page_builder_post_loop_widget = class_exists('SiteOrigin_Panels_Widgets_PostLoop') && method_exists('SiteOrigin_Panels_Widgets_PostLoop', 'is_rendering_loop') && SiteOrigin_Panels_Widgets_PostLoop::is_rendering_loop();
        if ($jetpack_infinite_scroll_active && !$is_page_builder_post_loop_widget) {
            return;
        }
        global $wp_query, $post;
        // Don't print empty markup on single pages if there's nowhere to navigate.
        if (is_single()) {
            $previous = is_attachment() ? get_post($post->post_parent) : get_adjacent_post(false, '', true);
            $next = get_adjacent_post(false, '', false);
            if (!$next && !$previous) {
                return;
            }
        }
        // Don't print empty markup in archives if there's only one page.
        if ($wp_query->max_num_pages < 2 && (is_home() || is_archive() || is_search())) {
            return;
        }
        // Add the shorten title filter
        add_filter('the_title', 'vantage_content_nav_shorten_title');
        $nav_class = 'site-navigation paging-navigation';
        if (is_single()) {
            $nav_class = 'site-navigation post-navigation';
        }
        ?>
	<nav role="navigation" id="<?php 
        echo esc_attr($nav_id);
        ?>
" class="<?php 
        echo $nav_class;
        ?>
">
		<h1 class="assistive-text"><?php 
        _e('Post navigation', 'vantage');
        ?>
</h1>

	<?php 
        if (is_single()) {
            // navigation links for single posts
            ?>

		<div class="single-nav-wrapper">
			<?php 
            previous_post_link('<div class="nav-previous">%link</div>', '<span class="meta-nav">' . _x('&larr;', 'Previous post link', 'vantage') . '</span> %title');
            ?>
			<?php 
            next_post_link('<div class="nav-next">%link</div>', '%title <span class="meta-nav">' . _x('&rarr;', 'Next post link', 'vantage') . '</span>');
            ?>
		</div>

	<?php 
        } elseif ($wp_query->max_num_pages > 1 && (is_home() || is_archive() || is_search())) {
            // navigation links for home, archive, and search pages
            ?>

		<?php 
            vantage_pagination();
            ?>

	<?php 
        }
        ?>

	</nav><!-- #<?php 
        echo esc_html($nav_id);
        ?>
 -->
	<?php 
        // Remove the shorten title filter
        remove_filter('the_title', 'vantage_content_nav_shorten_title');
    }