Tell me more ×
WordPress Answers is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I have searched through this site and online foran answer to my problem and tried lots of different suggestions offered and nothing works - please help!


I'm using the WP-PageNavi plugin. With the code on my index-work.php page:

<?php query_posts('post_type=work'); ?>
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
    <div class="post">
        <div class="boxgrid captionfull">
            <?php the_post_thumbnail('work-thumb'); ?>
            <div class="cover boxcaption backopacity">
                <h3><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></h3>
                <?php the_excerpt(''); ?>
            </div>
        </div>
    </div>

<?php endwhile ?>

<div class="clearleft"></div>
<div class="post-nav">
    <?php if(function_exists('wp_pagenavi')) { wp_pagenavi(); } ?>  
</div>

<?php else : ?>

    <h2>Not Found</h2>
    <p>Sorry, but you are looking for something that isn't here.</p>

<?php endif; ?>

If I have more than 4 pieces of work and I click on the pagination link to go to the next page I get a 404 error. The URL appears as:

http://www.mbsgraphicdesign.com/work/page/2/

Any ideas on how to fix this?

The pagination does not work on my index-work.php page and I get the 404 error as above but if I click on one of the taxonomies in the sidebar, like Artists and go to:

http://www.mbsgraphicdesign.com/workcategories/artists/

The pagination works fine using the exact same code and I get taken to:

http://www.mbsgraphicdesign.com/workcategories/artists/page/2/

with no 404 error. Why does it work here but not on the index page and how do I solve this issue?

----------EDIT-------------

In case this is important I have my permalinks structure set as follows:

/%category%/%postname%/

If i change this to be:

/blog/%category%/%postname%/

all the pagination works fine through the work section but the URLS are all wrong - they look fine within the blog, but within my work pages I now get:

http://www.mbsgraphicdesign.com/blog/work/british-american-project/

I don't want the /blog bit to be there!

This is SO frustrating - can anyone help me with this?????

share|improve this question

closed as too localized by toscho Jul 18 '12 at 21:17

This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, see the FAQ.

1 Answer

Does this work?

<?php $paged = (get_query_var( 'paged' )) ? get_query_var( 'paged' ) : 1; ?>
<?php query_posts('paged=' . $paged . '&post_type=work&offset=0'); ?>

<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
    <div class="post">
        <div class="boxgrid captionfull">
            <?php the_post_thumbnail('work-thumb'); ?>
            <div class="cover boxcaption backopacity">
                <h3><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></h3>
                <?php the_excerpt(''); ?>
            </div>
        </div>
    </div>

<?php endwhile ?>

<div class="clearleft"></div>
<div class="post-nav">
    <?php if(function_exists('wp_pagenavi')) { wp_pagenavi(); } ?>  
</div>

<?php else : ?>

    <h2>Not Found</h2>
    <p>Sorry, but you are looking for something that isn't here.</p>

<?php endif; ?>

<?php wp_reset_query(); ?>

EDIT:

@Staffan-Estberg had a similar problem here: WP-PageNavi gives me a 404 when using WP Query

He solved it by installing the Category Pagination Fix plugin, perhaps this may work for you too? You could also add the plugin function to your theme functions.php file:

function remove_page_from_query_string($query_string) { 
    if ($query_string['name'] == 'page' && isset($query_string['page'])) {
        unset($query_string['name']);
        list($delim, $page_index) = split('/', $query_string['page']);
        $query_string['paged'] = $page_index;
    }
    return $query_string;
}
add_filter('request', 'remove_page_from_query_string');

Let us know if that works for you.

share|improve this answer
no this results in displaying "Not Found Sorry, but you are looking for something that isn't there" – Evie Milo Oct 19 '11 at 12:01
What about this: Change the query to $query_posts = new WP_Query(array ('post_type' => 'work', 'posts_per_page' => 4, 'paged' => $paged, 'offset' => 0)); and change the loop to this: if ($query_posts->have_posts()) : while ($query_posts->have_posts()) : $query_posts->the_post(); – Paul Oct 19 '11 at 12:05
This pulls in 4 posts but my pagination links have disappeared. – Evie Milo Oct 19 '11 at 12:08
Does it work if you change <?php if(function_exists('wp_pagenavi')) { wp_pagenavi(); } ?> to this: <?php if(function_exists('wp_pagenavi')) wp_pagenavi( array( 'query' => $query_posts ) ); ?> (combined with the changes in the comment above) ? – Paul Oct 19 '11 at 12:21
with this edit the pagination links reappear but I still get a 404 when trying to go to page 2 – Evie Milo Oct 19 '11 at 12:31
show 4 more comments

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