Here is the code for Here's the functioncode that generates the content with the query.renders posts and pagination inside that visual composer component
public function renderPosts( $atts, $content = null ) {
global $post;
setup_postdata($post);
extract( shortcode_atts( array(
'foo' => 5, //default of 5
'categoryslug' => 'news-views' // Currently news and views.
), $atts) );
// For getting the Query variable on a statcci front page, you have
// to use 'page' and not 'paged'. Weird.
$paged = ( get_query_var('page') ) ? get_query_var('page') : 1;
// Two things needed: Not using the game library,
// Definitely using the supplied slug.
// These are two objects.
$dontUse = get_category_by_slug('game-library');
$catUsed = get_category_by_slug($atts->categoryslug);
// Args for the custom query
$query_args = array(
'posts_per_page' => intval($foo),
'category__not_in' => $dontUse->term_id,
'cat' => $catUsed->term_id,
'page' => $paged
);
$custom_query = new WP_Query($query_args);
$output = '<div id="blogroll">';
while ( $custom_query->have_posts() ) : $custom_query->the_post();
$output .= "<div class='home_post col span_12 clear-both'>";
$output .= "<div class='col span_3'><a href='" . get_the_permalink() . "'>" . get_the_post_thumbnail(get_the_ID(), 'home_post_thumb') . "</a></div>";
$output .= "<div class='col span_9 col_last right-edge'>";
$output .= "<h2 class='home_post_header'>";
$output .= '<a href="' . get_the_permalink() . '">' . get_the_title() . "</a>";
$output .= "</h2>";
$output .= get_the_excerpt();
$output .= '<a class="home-more-link" href="' . get_the_permalink() . '"><span class="continue-reading">Read More</span></a>';
$output .= "</div>";
$output .= "</div>";
endwhile;
wp_reset_postdata();
// Pagination not working, but it outputs just fine?
$output .= '<div id="pagination" class="blogroll-pagination">' . home_pagination($custom_query) . '</div></div>';
wp_reset_query();
return $output;
}
function home_pagination($query = null) {
/*if ( !$query ) {
global $wp_query;
$query = $wp_query;
} commented out because do I need this? */
$big = 999999999; // need an unlikely integer
$pagination = paginate_links( array(
'base' => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ),
'format' => '?paged=%#%',
'current' => max( 1, get_query_var( 'page' ) ),
'total' => $query->max_num_pages,
'prev_text' => '« Previous',
'next_text' => 'Next »',
) );
return $pagination;
}