0

I have searched a lot now and not found a real solution that helps me with this:

I am creating a custom page template for an archive page. This (static) page will show all my blog posts ordered by year & months. I figured that this is already a long list of about 500 posts, so I decided that I would want a "paginated" archive page with 75 posts each. But i cannot figure out, how to use the <!--nextpage-->-shortcode in my php template. I inserted as show below, and it only works 50%. It "ends" the current page, but does not add the links for the following pages.

<div class="entry-content">
<?php
    $all_posts = get_posts(array(
        'posts_per_page' => -1 // to show all posts
    ));

    // this variable will contain all the posts in a associative array
    // with three levels, for every year, month and posts.

    $ordered_posts = array();
    $post_count = 0;

    foreach ($all_posts as $single) {
        $year  = mysql2date('Y', $single->post_date);
        $month = mysql2date('F', $single->post_date);

        // specifies the position of the current post
        $ordered_posts[$year][$month][] = $single;

    }

    // iterates the years
    foreach ($ordered_posts as $year => $months) { ?>
        <h2><?php echo $year ?></h2>
        <ul class="months" style="list-style-type: none;">
        <?php foreach ($months as $month => $posts ) { // iterates the moths ?>
            <li>
                <h3><?php printf("%s " . $year . " (%d)", $month, count($months[$month]));?></h3>
                <ul class="posts" style="list-style-type: none;">
                <?php if ( ! has_category( is_category( pinboard_get_option( 'portfolio_cat' ) ) ) ):
                foreach ($posts as $single ) { // iterates the posts ?>
                    <li>
                        <a href="<?php echo get_permalink($single->ID); ?>" class="article"><?php echo get_the_title($single->ID); ?></a> - <?php $categories = get_the_category($single->ID);
                        $separator = ' ';
                        $output = '';
                        if($categories){
                            foreach($categories as $category) {
                                    $output .= '<a href="'.get_category_link( $category->term_id ).'" title="' . esc_attr( sprintf( __( "View all posts in %s" ), $category->name ) ) . '" class="category">'.$category->cat_name.'</a>'.$separator.'['.$post_count.']';
                                }
                                echo trim($output, $separator);
                            }
                            $post_count++;
                            /*
                            if ( $post_count > 75 ):
                                return '<!--nextpage-->';
                            endif;
                            // Kinda works: ends "page" but does not add pagination
                            */
                            ?>
                    </li>
                <?php }
                endif; // ends foreach $posts ?>
                </ul> <!-- ul.posts -->
            </li>
        <?php } // ends foreach for $months ?>
        </ul> <!-- ul.months -->
    <?php } // ends foreach for $ordered_posts ?>
    <div class="clear"></div>
</div><!-- .entry-content -->
<?php wp_link_pages( array( 'before' => '<footer class="entry-utility"><p class="post-pagination">' . __( 'Pages:', 'pinboard' ), 'after' => '</p></footer><!-- .entry-utility -->' ) ); ?>
</div><!-- .entry -->
rob_st
  • 266
  • 2
  • 12

0 Answers0