I have Create a page that lists posts by category but only shows 5 posts from each category. how do I add a button in each category to display all posts?
Here's my code for a page that lists posts by category:
$categories = get_terms( 'category', 'orderby=name&order=ASC');
foreach ( $categories as $category ) {
echo '<h2 class="post-title">' . $category->name . '</h2>';
echo '<div class="post-list">';
// WP_Query arguments
$args = array(
'cat' => $category->term_id,
'orderby' => 'term_order',
);
// The Query
$query = new WP_Query( $args );
// The Loop
if ( $query->have_posts() ) {
while ( $query->have_posts() ) {
$query->the_post();
?>
<p><a href="<?php the_permalink();?>"><?php the_title(); ?></a></p>
<?php
} // End while
} // End if
echo '</div>';
// Restore original Post Data
wp_reset_postdata();
} // End foreach
'posts_per_page' => -1
to the$args
.$args = array( 'cat' => $category->term_id, 'posts_per_page' => -1, 'orderby' => 'term_order', );
I mean how to add code ( 'posts_per_page' => -1,) by clicking link or button. So will show all post. Can you help me!