0

Can't get the pagination to work. Here's my archive-work.php:

<?php get_header(); ?>

    <main role="main">
        <!-- section -->
        <section>

            <h1><?php _e( 'Work', 'html5blank' ); ?></h1>

            <?php get_template_part('loop', 'work'); ?>

            <?php get_template_part('pagination'); ?>

        </section>
        <!-- /section -->
    </main>

<?php get_sidebar(); ?>

<?php get_footer(); ?>

loop-work.php:

<?php

$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;

$work = array(
    'post_type' => 'work'
    ,'numberposts' => -1
    ,'posts_per_page' => 2
    ,'paged' => $paged
);

$loop = new WP_Query( $work );

if ($loop->have_posts()): while ($loop->have_posts()) : $loop->the_post(); ?>

    <!-- article -->
    <article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>

        <!-- post thumbnail -->
        <?php if ( has_post_thumbnail()) : // Check if thumbnail exists ?>
            <div class="thumbnail">
                <a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>">
                    <?php the_post_thumbnail(array(300,225)); // Declare pixel size you need inside the array ?>
                </a>
            </div>
        <?php endif; ?>
        <!-- /post thumbnail -->

        <header>
            <!-- post title -->
            <h2 class="title">
                <a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a>
            </h2>
            <!-- /post title -->
            <span class="date"><?php the_time('F Y'); ?></span>
        </header>

        <br/><br/>

        <!-- post details -->
        <!--span class="author"><?php _e( 'Published by', 'html5blank' ); ?> <?php the_author_posts_link(); ?></span-->
        <!--span class="comments"><?php if (comments_open( get_the_ID() ) ) comments_popup_link( __( 'Leave your thoughts', 'html5blank' ), __( '1 Comment', 'html5blank' ), __( '% Comments', 'html5blank' )); ?></span-->
        <!-- /post details -->

        <?php html5wp_excerpt('html5wp_index'); // Build your custom callback length in functions.php ?>

        <?php edit_post_link(); ?>

    </article>
    <!-- /article -->

<?php endwhile; ?>

<?php else: ?>

    <!-- article -->
    <article>
        <h2><?php _e( 'Sorry, nothing to display.', 'html5blank' ); ?></h2>
    </article>
    <!-- /article -->

<?php endif; ?>

If I set the default page to 2, it does show the 3rd and 4th entries... so why won't the links show? That's how it's set up in the theme's default archive/loop.

For your reference: https://github.com/toddmotto/html5blank

Thanks.

2
  • Also what's a good way of including a CPT archive/index in the regular menus? or making them available for inclusion? I can manually add the link, but then it isn't recognized as the current menu item/active.
    – user163831
    Oct 29 '14 at 0:29
  • code.tutsplus.com/tutorials/… Jul 11 '15 at 16:33
0

Most pagination relies on the $wp_query global. Try changing $loop to $wp_query

And put this wp_reset_postdata(); after the endwhile.

1
  • 2
    Well changing $loop to $wp_query did get the pagination to show up, but when I click, it says not found, and if I go to /?page=2 it still thinks it's page 1
    – user163831
    Oct 29 '14 at 0:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.