Ask your WordPress questions! Pay money and get answers fast! Comodo Trusted Site Seal
Official PayPal Seal

404 error on next_posts_link on category page WordPress

  • SOLVED

Hi,

I get an 404 error - not found page when i click on the next_post_link or previous post link on a category page.

Link: http://www.nono.be/huisstijlen-en-drukwerk/
Error page: http://www.nono.be/huisstijlen-en-drukwerk/page/2/

See the code below

Any way how I can fix this?

Thanks for the quick response.

Gr.
Filip



<?php
/*
Template Name: Home
*/
?>
<?php get_header(); ?>

<div id="content">
<div class="row" style="width:950px; margin:0 auto">
<div class="column-left" style="border:none">
<h2><img src="<?php bloginfo('template_directory'); ?>/img/tit-huisstijlen-en-drukwerk.png" alt="Nono blogt"/></h2>
<?php
$my_id = 290;
$post_id_290 = get_post($my_id);
$content = $post_id_290->post_content;
$content = apply_filters('the_content', $content);
$content = str_replace(']]>', ']]>', $content);
echo $content;
?>
</div>
<div class="column-right">
<?php
$postslist = get_posts('numberposts=4&order=DESC&orderby=date&category=11');
foreach ($postslist as $post) :
setup_postdata($post);
?>
<div class="post">
<div class="square-info">
<div class="v-outer">
<div class="v-middle">
<div class="v-inner"> <a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>">
<h2>
<?php the_title(); ?>
</h2>
<p>
<?php $key="Label"; echo get_post_meta($post->ID, $key, true); ?>
</p>
</a> </div>
</div>
</div>
</div>
<div class="square-img"> <a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>">
<?php the_post_thumbnail(); ?>
</a> </div>
</div>
<?php endforeach; ?>
</div>
<div class="clear"></div>
</div>
<hr class="line-horizontal-001">
<div class="row" style="padding-top: 15px">
<div class="archive">
<h2><img src="<?php bloginfo('template_directory'); ?>/img/tit-ontdek-onze-portfolio.png" /></h2>
<?php

$row = 1;

?>
<?php while (have_posts()) : the_post(); ?>
<?php

$postCount=$postCount+1;

?>
<div <?php post_class() ?>>
<?php

if($row&1){

?>
<div class="square-info">
<div class="v-outer">
<div class="v-middle">
<div class="v-inner"> <a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>">
<h2 id="post-<?php the_ID(); ?>">
<?php the_title(); ?>
</h2>
<p>
<?php $key="Label"; echo get_post_meta($post->ID, $key, true); ?>
</p>
</a> </div>
</div>
</div>
</div>
<div class="img"><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>">
<?php the_post_thumbnail(); ?>
</a></div>
<?php

} else {

?>
<div class="img" style="margin-right:10px"><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>">
<?php the_post_thumbnail(); ?>
</a></div>
<div class="square-info" style="margin-right:0px">
<div class="v-outer">
<div class="v-middle">
<div class="v-inner"> <a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>">
<h2 id="post-<?php the_ID(); ?>">
<?php the_title(); ?>
</h2>
<p>
<?php $key="Label"; echo get_post_meta($post->ID, $key, true); ?>
</p>
</a> </div>
</div>
</div>
</div>
<?php

}

?>
</div>
<?php

if (($postCount % 4) == 0 ) {
$row = $row+1;
$postCount=0;

}

?>
<?php endwhile; ?>
<div class="clear"></div>
<div class="next-post-link">
<?php next_posts_link('Vorige') ?>
</div>
<div class="previous-post-link">
<?php previous_posts_link('Volgende') ?>
</div>
</div>
<div class="clear"></div>
<hr class="line-horizontal-002">
</div>
</div>
<div class="clear"></div>
</div>
<?php get_footer(); ?>


Answers (2)

2010-12-27

Michael Fields answers:

Hi. IMHO it is poor form to use a page template to display multiple posts. Category templates are designed to accomplish exactly what you need without producing errors such as you are experiencing here. I would start by saving this code as category-11.php and re-working it. previous_posts_link() and previous_posts_link() are not designed to work in this context


Filip Van Reeth comments:

Hmm,

Thanks for the information.
I use the category.php to check which category it is and redirect to the right category design template.


<?php
if ( is_category( array ( 11 ) ) ) {
include(TEMPLATEPATH . '/category-01.php');
}

elseif ( is_category( array ( 12 ) ) ) {
include(TEMPLATEPATH . '/category-02.php');
}

else {
include(TEMPLATEPATH . '/category-default.php');
}
?>



How do you think I can fix this?
Does renaming it will solve the problem?

Thank for the quick response ;-)


Michael Fields comments:

No problem. Actually, there is no need to have a file like this at all, it may actually cause problems in the future... WordPress handles all of this for you. I would suggest reading over the template hierarchy Codex page mainly the category template section: http://codex.wordpress.org/Template_Hierarchy#Category_display

As for you original question, if you save the page template you posted above (don't forget to delete the template comment from the top) and save it as category-11.php WordPress will automatically include it when category 11 is queried for.


Filip Van Reeth comments:

Hi,

Renamed it to category-11 & category-12.php.
Removed the category.php file.
Removed the template comment.

Still get the error? Or is there something wrong with the code?
Thanks for the help.

Gr.


Michael Fields comments:

Try these, They work fine for me:
http://www.nono.be/category/huisstijlen-en-drukwerk/
http://www.nono.be/category/huisstijlen-en-drukwerk/page/2/


Filip Van Reeth comments:

Thx.
Is there any way to remove the /category/ in the url?
Just so it says www.nono.be/huisstijlen-en-drukwerk


Filip Van Reeth comments:

Thx.
Is there any way to remove the /category/ in the url?
Just so it says www.nono.be/huisstijlen-en-drukwerk


Michael Fields comments:

I would suggest that you try this plugin:

[[LINK href="http://wordpress.org/extend/plugins/wp-htaccess-control/"]]http://wordpress.org/extend/plugins/wp-htaccess-control/[[/LINK]]

It is compatible with current version of WordPress


Filip Van Reeth comments:

Sebastien also mentioned a plugin that works.
I asked him if there is any way to do this native without a plugin?
Just for information.


Michael Fields comments:

Not without a plugin or similar code.


Filip Van Reeth comments:

Ok, thanks for the information.
I'm just waiting for the answer of Sebastien.
Then I will select a winner ;-)

2010-12-27

Sébastien | French WordpressDesigner answers:

Filip,

1-in your file, erase this


<?php

/*

Template Name: Home

*/

?>

2-save your file as category-11.php

3-not delete category.php
4-in category.php erase :
<?php

if ( is_category( array ( 11 ) ) ) {

include(TEMPLATEPATH . '/category-01.php');

}



elseif ( is_category( array ( 12 ) ) ) {

include(TEMPLATEPATH . '/category-02.php');

}



else {

include(TEMPLATEPATH . '/category-default.php');

}

?>



the content of this page http://www.nono.be/huisstijlen-en-drukwerk/ is now generate by category-11.php, so if you want see this page you must use the url of the category 11 which is probably : http://www.nono.be/category/huisstijlen-en-drukwerk/


Filip Van Reeth comments:

Thx.
Is there any way to remove the /category/ in the url?
Just so it says www.nono.be/huisstijlen-en-drukwerk


Sébastien | French WordpressDesigner comments:

you can use this plugin : http://wordpress.org/extend/plugins/wp-no-category-base/


Filip Van Reeth comments:

Thx.
Works like a charm.
Do you know any way to do this native (without a plugin)?
Just for information ;-)


Sébastien | French WordpressDesigner comments:

i think there is no way