<?php
/*
 * @package WordPress
 * @subpackage Campoal
 */

global $campoal_options;
$posts_per_page         = isset($campoal_options['conikal_petitions_per_page_field']) ? $campoal_options['conikal_petitions_per_page_field'] : 10;

$petitions_by_tag       = conikal_petitions_taxonomy_query();
$total                  = $petitions_by_tag->found_posts;

if ( $petitions_by_tag->have_posts() ) :
    while( $petitions_by_tag->have_posts() ) : $petitions_by_tag->the_post();
        /*
         * Include the petition template for the content.
         * If you want to override this in a child theme, then include a file
         */
        get_template_part('loop/content-petition', 'list');
    endwhile; ?>

    <!-- PAGINATION -->
    <?php conikal_pagination_buttons(_n('Petition', 'Petitions', $total, 'campoal'), $petitions_by_tag->max_num_pages, $total, $posts_per_page) ?>
<?php else :
    $petitions_by_tag  = conikal_petitions_taxonomy_query('WORLD');
    $total                  = $petitions_by_tag->found_posts;

    if ( $petitions_by_tag->have_posts() ) :
        // display not found post notice
        conikal_not_found_post(__('The country you selected has no campaigns found.', 'campoal'), __("No campaigns in your country, global campaigns are shown instead.", 'campoal'), 'warning', 'globe icon');
        
        // loop the petition founded
        while( $petitions_by_tag->have_posts() ) : $petitions_by_tag->the_post();
            /*
             * Include the petition template for the content.
             * If you want to override this in a child theme, then include a file
             */
            get_template_part('loop/content-petition', 'list');
        endwhile; ?>
    
        <!-- PAGINATION -->
        <?php conikal_pagination_buttons(_n('Petition', 'Petitions', $total, 'campoal'), $petitions_by_tag->max_num_pages, $total, $posts_per_page) ?>
    <?php else :
        // display not found post notice
        conikal_not_found_post(__('No campaigns found.', 'campoal'), __("We're sorry, but no campaigns matched your criteria.", 'campoal'));
    endif;
endif;
?>