<?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;

$forms_by_category  = conikal_give_category_query();
$total              = $forms_by_category->found_posts;

if ( $forms_by_category->have_posts() ) : ?>
    <div class="ui three stackable cards petition-cards">
        <?php while( $forms_by_category->have_posts() ) : $forms_by_category->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-give', 'grid');

        endwhile; ?>
    </div>

    <!-- PAGINATION -->
    <?php conikal_pagination_buttons(_n('Campaign', 'Campaigns', $total, 'campoal'), $forms_by_category->max_num_pages, $total, $posts_per_page) ?>
    
<?php else :
    $forms_by_category  = conikal_give_category_query('WORLD');
    $total          = $forms_by_category->found_posts;

    if ( $forms_by_category->have_posts() ) : 
        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');
        ?>
        <div class="ui section hidden divider"></div>
        <div class="ui three stackable cards petition-cards">
            <?php while( $forms_by_category->have_posts() ) : $forms_by_category->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-give', 'grid');
    
            endwhile; ?>
        </div>
    
        <!-- PAGINATION -->
        <?php conikal_pagination_buttons(_n('Campaign', 'Campaigns', $total, 'campoal'), $forms_by_category->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;
?>
<div class="ui section hidden divider"></div>