• Resolved Erich

    (@erichboileau)


    Hey,

    I am having a funny problem with pagination on my website.

    I am using the “exec php” plugin on the BigFeature theme to allow php code on my wordpress pages. Then I’m using the wp query function to pipe in specific posts and display them on my pages.

    I read that there was a problem with pagination when using custom queries, and I so I used this code to fix it:

    <h3>Recent Articles</h3>
    <ul>
    <?php
    $temp = $wp_query;
    $wp_query= null;
    $wp_query = new WP_Query();
    $wp_query->query('showposts=5'.'&paged='.$paged);
    ?>
    <?php while ($wp_query->have_posts()) : $wp_query->the_post(); ?>
    	<li><a href="<?php the_permalink() ?>" rel="bookmark"><?php the_title(); ?></a></li>
    <?php endwhile; ?>
    </ul>
    <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;?>

    But now, the page navigation is not showing up at all. I’m just getting five posts and then nothing(example): https://www.remainnameless.org/resources/artists/

    Any ideas? Thanks!

Viewing 6 replies - 1 through 6 (of 6 total)
  • I don’t see where you are setting $paged. Try setting it like this:

    $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
    $wp_query  = new WP_Query();
    Thread Starter Erich

    (@erichboileau)

    Thanks vtxyzzy,

    Added that line, but I didn’t seem to get any results. I suspect this problem may have something to do with calling a custom query from a WordPress “page.” Others I’ve seen working on this problem seem to be using .php files, whereas my code is being processed through the CMS.

    My understanding of php is already quite limited. Here’s the original code that I started with. This code works, but it lacks pagination. Any ideas on what exactly I could add to this would be super helpful!

    <h1><img src="https://www.remainnameless.org/wp-content/uploads/2010/02/articles.png" alt="" title="articles" width="48" height="48" style="vertical-align: middle;" />&nbsp;ARTICLES</h1>
    <p>&nbsp;</p>
    <div class="pagebox">
    <h4>ALL ARTICLES &amp AUTHORS</h4>
    <?php query_posts('category_name=articles&orderby=title&nopaging=true'); ?><?php while (have_posts()) : the_post(); ?><h3><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h3><?php content(25); ?>
    <?php endwhile; ?><?php wp_reset_query(); ?>
    </div>

    Thanks so much in advance. Sorry to be a bother, but I’ve searched the forums and I’m so surprised that I’m the only one with this specific problem. I figure I must be doing something bone-headed.

    Hi,

    For pagination, please check with this plugin:

    https://www.ads-software.com/extend/plugins/wordpress-navigation-list-plugin-navt/

    Also refer this article:

    https://codex.www.ads-software.com/Next_and_Previous_Links

    Thanks,

    Shane G.

    Give this a try:

    <h1><img src="https://www.remainnameless.org/wp-content/uploads/2010/02/articles.png" alt="" title="articles" width="48" height="48" style="vertical-align: middle;" />&nbsp;ARTICLES</h1>
    <p>&nbsp;</p>
    <div class="pagebox">
    <h4>ALL ARTICLES &amp AUTHORS</h4>
    <?php
    $paged = (intval(get_query_var('paged'))) ? intval(get_query_var('paged')) : 1;
    query_posts('category_name=articles&orderby=title&paged=' . $paged); ?><?php while (have_posts()) : the_post(); ?><h3><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h3><?php content(25); ?>
    <?php endwhile; ?><?php wp_reset_query(); ?>
    </div>
    Thread Starter Erich

    (@erichboileau)

    Ah! I think I got it working. Thanks for the snippet, vtx. I just added the generic:

    <div class="navigation">
      <div class="alignleft"><?php previous_posts_link('&laquo; Previous') ?></div>
      <div class="alignright"><?php next_posts_link('More &raquo;') ?></div>
    </div>

    …just below the code you gave me, and I think I’m seeing workable results. Once I get things cleaned up, I’ll post the full code for anyone who’s been following.

    Thread Starter Erich

    (@erichboileau)

    Final code. I have a couple of loops going on this page:

    <h1><img src="https://www.remainnameless.org/wp-content/uploads/2010/02/articles.png" alt="" title="articles" width="48" height="48" style="vertical-align: middle;" />&nbsp;ARTICLES</h1>
    <p>&nbsp;</p>
    <div class="pagebox">
    <h4>RECENT ARTICLES & AUTHORS</h4>
    <?php query_posts('category_name=articles&orderby=modified&showposts=2&order=DESC'); ?><?php while (have_posts()) : the_post(); ?><h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
    <?php
    if ( has_excerpt() ) {
         excerpt(40);
    }
    else {
         echo('&nbsp;');
    }
    ?>
    <?php endwhile; ?><?php wp_reset_query(); ?>
    <p>&nbsp;</p>
    
    <h4>ALL ARTICLES & AUTHORS</h4>
    <?php
    $paged = (intval(get_query_var('paged'))) ? intval(get_query_var('paged')) : 1;
    query_posts('category_name=articles&orderby=title&posts_per_page=5&paged=' . $paged); ?><?php while (have_posts()) : the_post(); ?><h3><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h3>
    <?php
    if ( has_excerpt() ) {
         excerpt(35);
    }
    else {
         echo('&nbsp;');
    }
    ?>
    <?php endwhile; ?>
    <div class="clear"></div>
    	<div class="pagenavigation">
    		<?php if(function_exists('wp_pagenavi')) { wp_pagenavi(); } elseif (function_exists('wp_page_numbers')) { wp_page_numbers(); } else { ?>
    		<div class="alignleft"><?php next_posts_link(__('&laquo; Older Entries','BigFeature')) ?></div>
    		<div class="alignright"><?php previous_posts_link(__('Newer Entries &raquo;','BigFeature')) ?></div>
    		<?php } ?>
    	</div>
    <?php wp_reset_query(); ?>
    </div>
Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Pagination Doesn’t Work Within Page Posts’ is closed to new replies.