<?php
global $campoal_options;

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


    // get current author
    $curauth = (isset($_GET['author_name'])) ? get_user_by('slug', $author_name) : get_userdata(intval($author));

    if ($user_is_author) {
        $author_petitions = conikal_my_petitions($curauth->ID);
    } else {
        $author_petitions = conikal_author_petitions($curauth->ID);
    }

    // get total posts founded
    if($author_petitions->have_posts()) {
        $total_p = $author_petitions->found_posts;
    } else {
        $total_p = 0;
    }
    // display petition's author
    if ($author_petitions->have_posts()) : ?>
        <div id="content">
            <?php while($author_petitions->have_posts()) : $author_petitions->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; ?>
        </div>
        <div class="ui hidden divider"></div>
        
        <!-- LOAD MORE BUTTON -->
        <button class="ui basic fluid large button" id="load-more" data-page="2" data-number="<?php echo esc_attr($posts_per_page) ?>" data-author="<?php echo esc_attr($curauth->ID) ?>" data-type="<?php echo esc_attr($user_is_author ? 'conikal_load_my_petitions' : 'conikal_load_author_petitions') ?>"><i class="long arrow down icon"></i><?php esc_html_e('Load more...', 'campoal'); ?></button>     
    <?php else :
        // display not found post notice
        conikal_not_found_post(__('No campaigns found.', 'campoal'), __("We're sorry, but no campaigns have been started yet.", 'campoal'));
    endif; ?>

<?php if ($tab === 'signed' && ($signed_author_page == 1 || $user_is_author)) :
    $signed_petitions = conikal_signed_petitions($curauth->ID);

    // get total posts founded
    if($signed_petitions) {
        $total_p = $signed_petitions->found_posts;
    } else {
        $total_p = 0;
    }

    // display petition's author
    if($signed_petitions) : ?>
        <div id="content">
            <?php while($signed_petitions->have_posts() ) : $signed_petitions->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; ?>
        </div>

        <div class="ui hidden divider"></div>

        <!-- LOAD MORE BUTTON -->
        <button class="ui basic fluid large button" id="load-more" data-page="2" data-number="<?php echo esc_attr($posts_per_page) ?>" data-author="<?php echo esc_attr($curauth->ID) ?>" data-type="conikal_load_signed_petitions"><i class="long arrow down icon"></i><?php esc_html_e('Load more...', 'campoal'); ?></button>     
        
    <?php else :
        // display not found post notice
        conikal_not_found_post(__('No campaigns found.', 'campoal'), __("We're sorry, but no campaigns have been signed yet.", 'campoal'));
endif; ?>