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

Easy WP PHP Question WordPress

  • SOLVED

Right now I'm telling the code to pull up two posts per archive page in my portfolio category. But <strong>when I click the older entries button it doesn't find the other posts in that category, it sends me to my 404 error page</strong>. I need to get the other posts to show when I click older entries. <strong>The person with the best answer will provide me with the entire page code, as I do not like playing with PHP.</strong>

Link: [[LINK href="http://lucaswynne.com/category/portfolio/"]]http://lucaswynne.com/category/portfolio/[[/LINK]]

Extra note: I want to still be able to use WP's settings to show a maximum number of posts and don't want those settings to affect my portfolio page.


<?php get_header(); ?>

<div id="portfolio_content">

<!-- Grab posts -->
<?php if (query_posts('posts_per_page=2')) : ?>
<?php while (have_posts()) : the_post(); ?>


<div style="width:980px; background:#000">

<div class="img">
<a href="<?php the_permalink() ?>">
<?php $image = catch_that_image();
if( $image ) { ?>
<img src="<?php echo $image; ?>" alt="<?php the_title(); ?>" title="<?php the_title(); ?>, <?php comments_number('No comments','One comment','% comments'); ?>" />
<?php } ?>
</a>
<div class="title"><?php the_title(); ?></div>
<div class="desc">Add a description of the image here</div>
</div>

</div>

<?php endwhile; ?>
<?php endif; ?>


<!-- Next/Previous Posts -->
<div class="mp_archive">
<div id="more_posts">
<div class="oe"><?php next_posts_link('« Older Entries') ?></div><div class="re"><?php previous_posts_link ('Recent Entries »') ?></div>
</div>
</div>



</div>
</div>
<?php get_footer(); ?>

Answers (8)

2010-12-20

Sébastien | French WordpressDesigner answers:

replace
<?php if (query_posts('posts_per_page=2')) : ?>
by
< ?php query_posts($query_string . '&posts_per_page=2'); ?>


Lucas Wynne comments:

I can't get this to work, unless I need to replace one of the ending PHP codes also?


Sébastien | French WordpressDesigner comments:

sorry, an error in my code.

replace


<?php if (query_posts('posts_per_page=2')) : ?>
<?php while (have_posts()) : the_post(); ?>

by

<?php query_posts('posts_per_page=2');
if ( have_posts() ) : while (have_posts()) : the_post(); ?>



Lucas Wynne comments:

I think we're getting close here. But when I do this it doesn't show the other posts, but rather just repeats the same posts. Take a look: [[LINK href="http://lucaswynne.com/category/portfolio/page/2/"]]http://lucaswynne.com/category/portfolio/page/2/[[/LINK]]


Sébastien | French WordpressDesigner comments:

normal

you must use this code :

<?php query_posts($query_string . '&posts_per_page=2');

if ( have_posts() ) : while (have_posts()) : the_post(); ?>

2010-12-20

Maor Barazany answers:

Try this:

<?php get_header(); ?>

<div id="portfolio_content">

<!-- Grab posts -->

<?php if (query_posts('posts_per_page=2&paged='.$paged)) : ?>

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

<div style="width:980px; background:#000">

<div class="img">

<a href="<?php the_permalink() ?>">

<?php $image = catch_that_image();

if( $image ) { ?>

<img src="<?php echo $image; ?>" alt="<?php the_title(); ?>" title="<?php the_title(); ?>, <?php comments_number('No comments','One comment','% comments'); ?>" />

<?php } ?>

</a>

<div class="title"><?php the_title(); ?></div>

<div class="desc">Add a description of the image here</div>

</div>

</div>

<?php endwhile; ?>

<?php endif; ?>

<!-- Next/Previous Posts -->

<div class="mp_archive">

<div id="more_posts">

<div class="oe"><?php next_posts_link('« Older Entries') ?></div><div class="re"><?php previous_posts_link ('Recent Entries »') ?></div>

</div>
</div>

</div>
</div>

<?php get_footer(); ?>


Lucas Wynne comments:

Doesn't work.


Maor Barazany comments:

Try to re-save your permalinks structure


Lucas Wynne comments:

Still doesn't work.


Lucas Wynne comments:

I believe for whatever reason the code I'm using is telling WP there are only 2 posts to be found, not to just show 2 posts on the page.


Maor Barazany comments:

Try instead this -


<?php if (query_posts('posts_per_page=2&paged='.$paged)) : ?>
<?php while (have_posts()) : the_post(); ?>


have this -

<?php query_posts('posts_per_page=2&paged='.$paged);
if (have_posts()) :
while (have_posts()) : the_post(); ?>

2010-12-20

Ali Hussain answers:

Try replacing

<?php if (query_posts('posts_per_page=2')) : ?>

with

<?php if (query_posts('posts_per_page=2, 'showposts' => -1')) : ?>


Lucas Wynne comments:

Does not work.


Ali Hussain comments:

Try this

<?php get_header(); ?>



<div id="portfolio_content">




<!-- Grab posts -->

<?php
$my_query = new WP_Query('posts_per_page=2');
while ($my_query->have_posts()):
$my_query->the_post();?>





<div style="width:980px; background:#000">



<div class="img">

<a href="<?php the_permalink() ?>">

<?php $image = catch_that_image();

if( $image ) { ?>

<img src="<?php echo $image; ?>" alt="<?php the_title(); ?>" title="<?php the_title(); ?>, <?php comments_number('No comments','One comment','% comments'); ?>" />

<?php } ?>

</a>

<div class="title"><?php the_title(); ?></div>

<div class="desc">Add a description of the image here</div>

</div>



</div>



<?php endwhile; ?>

<?php endif; ?>





<!-- Next/Previous Posts -->

<div class="mp_archive">

<div id="more_posts">

<div class="oe"><?php next_posts_link('« Older Entries') ?></div><div class="re"><?php previous_posts_link ('Recent Entries »') ?></div>

</div>

</div>







</div>

</div>

<?php get_footer(); ?>


Lucas Wynne comments:

Creates this error:
Parse error: syntax error, unexpected T_ENDIF in /home/consumer/public_html/lucaswynne.com/wp-content/themes/Topper/category-portfolio.php on line 105

2010-12-20

Lew Ayotte answers:

Try this...

<?php get_header(); ?>

<div id="portfolio_content">
<!-- Grab posts -->

<?php $paged = (get_query_var('paged')) ? get_query_var('paged') : 1; ?>
<?php if (query_posts('posts_per_page=2&paged='.$paged)) : ?>
<?php while (have_posts()) : the_post(); ?>
<div style="width:980px; background:#000">
<div class="img"> <a href="<?php the_permalink() ?>">
<?php $image = catch_that_image();

if( $image ) { ?>
<img src="<?php echo $image; ?>" alt="<?php the_title(); ?>" title="<?php the_title(); ?>, <?php comments_number('No comments','One comment','% comments'); ?>" />
<?php } ?>
</a>
<div class="title">
<?php the_title(); ?>
</div>
<div class="desc">Add a description of the image here</div>
</div>
</div>
<?php endwhile; ?>
<?php endif; ?>
<!-- Next/Previous Posts -->
<div class="mp_archive">
<div id="more_posts">
<div class="oe">
<?php next_posts_link('« Older Entries') ?>
</div>
<div class="re">
<?php previous_posts_link ('Recent Entries »') ?>
</div>
</div>
</div>
</div>
</div>
<?php get_footer(); ?>


Lucas Wynne comments:

Doesn't work.


Lew Ayotte comments:

You don't have any caching plugins activated, do you?


Lucas Wynne comments:

Nope, I don't.


Lew Ayotte comments:

Do you have any custom permalinks setup?

http://wordpress.org/support/topic/paged-causes-404-error?replies=10


Lucas Wynne comments:

Changing the permalinks with my code, changing the permalinks with other codes provided also doesn't work. And I've tried everything found on that forum post with both my code and the codes provided here.


Lucas Wynne comments:

I believe for whatever reason the code I'm using is telling WP there are only 2 posts to be found, not to just show 2 posts on the page.


Lew Ayotte comments:

What version of WP? Unless there is some undocumented bug, it doesn't make sense that it would only think there are only 2 posts. Plus if it only found 2, it shouldn't show the "Older Entries" link


Lucas Wynne comments:

3.0.3


Lucas Wynne comments:

Maybe this will help narrow it down:
I have found when I simply use <?php if (query_posts('posts_per_page=')) : ?>
<?php while (have_posts()) : the_post(); ?>

and set the maximum number of posts in my settings to 3 it displays the same posts on the older/newer pages and does not display the other posts.

2010-12-20

Pali Madra answers:

Hello instead of

<?php if (query_posts('posts_per_page=2')) : ?>

try

<?php if (query_posts('posts_per_page'=>2')) : ?>

Hope this works!


Lucas Wynne comments:

Creates this error:
Parse error: syntax error, unexpected T_DOUBLE_ARROW in /home/consumer/public_html/lucaswynne.com/wp-content/themes/Topper/category-portfolio.php on line 7


Pali Madra comments:

I wanted to clarify if you are using custom post types.


Pali Madra comments:

If you are using custom post types then ensure that the custom post types and page name are not the same.


Lucas Wynne comments:

I can't find any such conflict.


Lucas Wynne comments:

I believe for whatever reason the code I'm using is telling WP there are only 2 posts to be found, not to just show 2 posts on the page.

2010-12-20

idt answers:

Seems to be related to this: http://www.iriswebsolutions.in/blog/86/how-to-fix-wordpress-pagination-404-error/

2010-12-20

Buzu B answers:

Try this:



<?php get_header(); ?>



<div id="portfolio_content">



<!-- Grab posts -->
<?php
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
?>

<?php if (query_posts("posts_per_page=2&paged=$paged")) : ?>

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





<div style="width:980px; background:#000">



<div class="img">

<a href="<?php the_permalink() ?>">

<?php $image = catch_that_image();

if( $image ) { ?>

<img src="<?php echo $image; ?>" alt="<?php the_title(); ?>" title="<?php the_title(); ?>, <?php comments_number('No comments','One comment','% comments'); ?>" />

<?php } ?>

</a>

<div class="title"><?php the_title(); ?></div>

<div class="desc">Add a description of the image here</div>

</div>



</div>



<?php endwhile; ?>

<?php endif; ?>





<!-- Next/Previous Posts -->

<div class="mp_archive">

<div id="more_posts">

<div class="oe"><?php next_posts_link('« Older Entries') ?></div><div class="re"><?php previous_posts_link ('Recent Entries »') ?></div>

</div>

</div>







</div>

</div>

<?php get_footer(); ?>




Recommended procedure:

1)Name your file from

current_name.php

to

current_name.php.bak

2)Create a new file and save it as

current_name.php

in the current file location.

3)Paste the code that I just gave you and save your file

4)If the code does not work, delete current_file.php and change current_file.php.bak back to current_file.php

In this instructions replace current_file for the actual name of your file (for example page.php).

2010-12-20

Peter Michael answers:

Follow [[LINK href="http://weblogtoolscollection.com/archives/2008/04/13/define-your-own-wordpress-loop-using-wp_query/"]]this[[/LINK]] post.