Download free stock photos on Dreamstime. Free registration

Old 07-07-2009, 12:23   #1 (permalink)
Pete Nice
Crankshaft
 
Pete Nice's Avatar
 
Join Date: Apr 2003
Posts: 2,103
wordpress pagination

So I found a tutorial about pagination - I set it up with the if have_posts loop but ti doesn't work. If I take out the if and else statements it works - the only problem with that is the else statement contains the 'no post - go back to the homepage' message. Anyone else have a solution to pagination?
  Reply With Quote
Old 07-07-2009, 14:20   #2 (permalink)
anniegurl24
The Awesome One
 
anniegurl24's Avatar
 
Join Date: Jun 2009
Location: San Diego
Posts: 17
Send a message via AIM to anniegurl24
Code?
  Reply With Quote
Old 07-07-2009, 17:00   #3 (permalink)
bazzle
Don't touch my tea!
 
bazzle's Avatar
 
Join Date: Aug 2007
Posts: 1,678
Send a message via MSN to bazzle
Put this line into the loop, just after the_content

PHP Code:
<?php wp_link_pages(array('before' => '<p><strong>Pages:</strong> ''after' => '</p>''next_or_number' => 'number')); ?>


You shouldn't have to take out the if and else statements, or mess around with any other elements of the loop.
__________________
  Reply With Quote
Old 08-07-2009, 04:24   #4 (permalink)
Pete Nice
Crankshaft
 
Pete Nice's Avatar
 
Join Date: Apr 2003
Posts: 2,103
bazzle my nizzle - that didn't work - will post my code shortly.
  Reply With Quote
Old 08-07-2009, 04:49   #5 (permalink)
Pete Nice
Crankshaft
 
Pete Nice's Avatar
 
Join Date: Apr 2003
Posts: 2,103
so this is the code with Bazzle's pagination code added that doesn't work:

PHP Code:
<?php if (have_posts()) : ?>

        <?php $the_query = new WP_Query('showposts=10&orderby=post_date&order=desc');
            while (
$the_query->have_posts()) : $the_query->the_post();
            
$do_not_duplicate $post->ID?>
        <div id="post_date"><?php the_time('M'?><br /><span><?php the_time('d'?></span></div>
        <div id="post_title"><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></div>
        <div id="post_author">posted by <?php the_author() ?></div>
        <div id="post_comment"><?php edit_post_link('edit'''' '); ?><?php comments_popup_link('comment''1 comment''% comments'); ?></div>
        <div <?php post_class() ?> id="post-<?php the_ID(); ?>">
        <div class="entry">
        <?php the_content('Read the rest of this entry &raquo;'); ?>
        <p class="postmetadata"><?php the_tags('Tags: '', ''<br />'); ?></p>
        </div>
        </div>
        <?php endwhile; ?>
            <div class="navigation">
            <?php wp_link_pages(array('before' => '<p><strong>Pages:</strong> ''after' => '</p>''next_or_number' => 'number')); ?>
        </div>
        <?php else : ?>
        <div id="search_amount">Lost? Go back to the <a href="<?php echo get_option('home'); ?>/">home page</a></div>
        <?php endif; ?>

this is the tutorial code that works but doesn't include the if statements

PHP Code:
<?php $temp $wp_query
        
$wp_querynull
        
$wp_query = new WP_Query(); 
        
$wp_query->query('showposts=5'.'&paged='.$paged); ?> 
        <?php while ($wp_query->have_posts()) : $wp_query->the_post(); ?>
            $do_not_duplicate = $post->ID; ?>
        <div id="post_date"><?php the_time('M'?><br /><span><?php the_time('d'?></span></div>
        <div id="post_title"><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></div>
        <div id="post_author">posted by <?php the_author() ?></div>
        <div id="post_comment"><?php edit_post_link('edit'''' '); ?><?php comments_popup_link('comment''1 comment''% comments'); ?></div>
        <div <?php post_class() ?> id="post-<?php the_ID(); ?>">
        <div class="entry">
        <?php the_content('Read the rest of this entry &raquo;'); ?>
        <p class="postmetadata"><?php the_tags('Tags: '', ''<br />'); ?></p>
        </div>
        </div>
        <?php endwhile; ?>
            <div class="navigation">
            <div class="alignleft"><?php previous_posts_link('&laquo; Previous'?></div>
            <div class="alignright"><?php next_posts_link('More &raquo;'?></div>
            </div>
        <?php $wp_query null$wp_query $temp;?>

the same code within the if statements that gives me the 'next entries' link but when clicked I get the if statement 'no post - go to the homepage'

PHP Code:
<?php if (have_posts()) : ?>
        <?php $temp $wp_query
        
$wp_querynull
        
$wp_query = new WP_Query(); 
        
$wp_query->query('showposts=5'.'&paged='.$paged); ?> 
        <?php while ($wp_query->have_posts()) : $wp_query->the_post(); ?>
            $do_not_duplicate = $post->ID; ?>
        <div id="post_date"><?php the_time('M'?><br /><span><?php the_time('d'?></span></div>
        <div id="post_title"><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></div>
        <div id="post_author">posted by <?php the_author() ?></div>
        <div id="post_comment"><?php edit_post_link('edit'''' '); ?><?php comments_popup_link('comment''1 comment''% comments'); ?></div>
        <div <?php post_class() ?> id="post-<?php the_ID(); ?>">
        <div class="entry">
        <?php the_content('Read the rest of this entry &raquo;'); ?>
        <p class="postmetadata"><?php the_tags('Tags: '', ''<br />'); ?></p>
        </div>
        </div>
        <?php endwhile; ?>
            <div class="navigation">
            <div class="alignleft"><?php previous_posts_link('&laquo; Previous'?></div>
            <div class="alignright"><?php next_posts_link('More &raquo;'?></div>
            </div>
        <?php $wp_query null$wp_query $temp;?>
            <?php else : ?>
        <div id="search_amount">Lost? Go back to the <a href="<?php echo get_option('home'); ?>/">home page</a></div>
        <?php endif; ?>

Last edited by Pete Nice : 08-07-2009 at 05:09.
  Reply With Quote
Old 08-07-2009, 06:35   #6 (permalink)
Pete Nice
Crankshaft
 
Pete Nice's Avatar
 
Join Date: Apr 2003
Posts: 2,103
sorted it out - used the custom loop from the tutorial and added a 404.php to deal with pages that don't exist.
  Reply With Quote
Old 08-07-2009, 11:17   #7 (permalink)
Pete Nice
Crankshaft
 
Pete Nice's Avatar
 
Join Date: Apr 2003
Posts: 2,103
ok slags and byatches - thanks so much for all your help on my earlier post - and as per usual I sorted it out myself. I do have another question - no doubt it will sit here for a few hours until I work it out with maybe a couple of non-helpful posts added.

I'm using this pagination query on my index page - now I need to get it to work on the archives page - just incase there's loads of posts in that month. Currently the query is ignoring the query string and just paginating all of the months rather than just the one being passed:

PHP Code:
$temp = $wp_query; 
        $wp_query= null;
        $wp_query = new WP_Query(); 
        $wp_query->query('showposts=6'.'&paged='.$paged); ?> 
        
           <div id="search_title"><?php the_time('F, Y'); ?></div>        
        <div id="search_amount"></div>
        
        <?php while ($wp_query->have_posts()) : $wp_query->the_post(); ?>
          
          <div id="post_date"><?php the_time('M'?><br /><span><?php the_time('d'?></span></div>
        <div id="post_title"><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></div>
        <div id="post_author">posted by <?php the_author() ?></div>
        <div id="search_res"></div>
         <?php endwhile; ?>
  Reply With Quote
Old 08-07-2009, 12:16   #8 (permalink)
doodleflip
Senior Member
 
doodleflip's Avatar
 
Join Date: Jan 2009
Posts: 458
A non-helpful post.
  Reply With Quote
Old 08-07-2009, 12:23   #9 (permalink)
Pete Nice
Crankshaft
 
Pete Nice's Avatar
 
Join Date: Apr 2003
Posts: 2,103
it's ok - Pete to the rescue - needed to add $query_string to the query:

PHP Code:
$wp_query->query($query_string.'&showposts=6'.'&paged='.$paged); ?> 

once last thing - if someone could help me pass the date to the next page in the pagination that would be great. Currently it sits outside the while loop so only works on the original query.
  Reply With Quote
Old 08-07-2009, 22:52   #10 (permalink)
bazzle
Don't touch my tea!
 
bazzle's Avatar
 
Join Date: Aug 2007
Posts: 1,678
Send a message via MSN to bazzle
Quote:
Originally Posted by Pete Nice
so this is the code with Bazzle's pagination code added that doesn't work:

PHP Code:
<?php if (have_posts()) : ?>

        <?php $the_query = new WP_Query('showposts=10&orderby=post_date&order=desc');
            while (
$the_query->have_posts()) : $the_query->the_post();
            
$do_not_duplicate $post->ID?>
        <div id="post_date"><?php the_time('M'?><br /><span><?php the_time('d'?></span></div>
        <div id="post_title"><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></div>
        <div id="post_author">posted by <?php the_author() ?></div>
        <div id="post_comment"><?php edit_post_link('edit'''' '); ?><?php comments_popup_link('comment''1 comment''% comments'); ?></div>
        <div <?php post_class() ?> id="post-<?php the_ID(); ?>">
        <div class="entry">
        <?php the_content('Read the rest of this entry &raquo;'); ?>
        <p class="postmetadata"><?php the_tags('Tags: '', ''<br />'); ?></p>
        </div>
        </div>
        <?php endwhile; ?>
            <div class="navigation">
            <?php wp_link_pages(array('before' => '<p><strong>Pages:</strong> ''after' => '</p>''next_or_number' => 'number')); ?>
        </div>
        <?php else : ?>
        <div id="search_amount">Lost? Go back to the <a href="<?php echo get_option('home'); ?>/">home page</a></div>
        <?php endif; ?>

It doesn't work because you pasted it outside the loop. Paste it above the endwhile and it should work, like this:


PHP Code:
<?php if (have_posts()) : ?>

        <?php $the_query = new WP_Query('showposts=10&orderby=post_date&order=desc');
            while (
$the_query->have_posts()) : $the_query->the_post();
            
$do_not_duplicate $post->ID?>
        <div id="post_date"><?php the_time('M'?><br /><span><?php the_time('d'?></span></div>
        <div id="post_title"><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></div>
        <div id="post_author">posted by <?php the_author() ?></div>
        <div id="post_comment"><?php edit_post_link('edit'''' '); ?><?php comments_popup_link('comment''1 comment''% comments'); ?></div>
        <div <?php post_class() ?> id="post-<?php the_ID(); ?>">
        <div class="entry">
        <?php the_content('Read the rest of this entry &raquo;'); ?>
        <p class="postmetadata"><?php the_tags('Tags: '', ''<br />'); ?></p>
<?php wp_link_pages(array('before' => '<p><strong>Pages:</strong> ''after' => '</p>''next_or_number' => 'number')); ?>
        </div>
        </div>
        <?php endwhile; ?>
            <div class="navigation">
        </div>
        <?php else : ?>
        <div id="search_amount">Lost? Go back to the <a href="<?php echo get_option('home'); ?>/">home page</a></div>
        <?php endif; ?>


I'm guessing you might want the page numbers to appear outside the loop for layout reasons. I wouldn't know how to go about that, but there's probably a way you can.
__________________
  Reply With Quote
Old 09-07-2009, 04:15   #11 (permalink)
Pete Nice
Crankshaft
 
Pete Nice's Avatar
 
Join Date: Apr 2003
Posts: 2,103
Bazzle - I tried it inside the loop and it doesn't work either - also - if it did work inside the loop I'd get next and previous links on each of the posts rather than at the end of all of the posts.
  Reply With Quote
Old 09-07-2009, 09:43   #12 (permalink)
bazzle
Don't touch my tea!
 
bazzle's Avatar
 
Join Date: Aug 2007
Posts: 1,678
Send a message via MSN to bazzle
meh.

I misunderstood what you wanted with pagination, the code I suggested is for when you have a single post and you want it divided into multiple pages with the page numbers at the bottom.
__________________
  Reply With Quote
Old 13-07-2009, 09:20   #13 (permalink)
PartDigital
Freelance Web Developer
 
PartDigital's Avatar
 
Join Date: Oct 2007
Posts: 151
  Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search


Contact Us - Web Design Forums - Archive
Web Hosting by Heart Internet, vBulletin © 2000-2009 Jelsoft Enterprises Limited.
Search Engine Optimization by vBSEO 3.0.0 RC8
Web Hosting by Heart Internet