how do I add a button in each category to display all posts?

Question

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
0
, Julham 4 days 0 Answers 31 views 0

Leave an answer