Wordpress Pagination for single.php -


i've implemented category-based numeric pagination in wordpress theme:

pagination

what i've done far create custom page template list of paginated excerpts. once user clicks on excerpt view full article i'd paginate list of returned articles displayed.

it's understanding achieved in theme's 'single.php', though may wrong.

the pagination works custom template, when try implementing custom query within single.php think pagination attempts find next page within article itself, not i'm trying achieve (because doesn't exist). i'd paginate though returned articles user may navigate next , previous 1 article in category next.

i've read bit next/previous links, i'd rather use blog post boutros abichedid - stole idea custom page template, , it's awesome!

i've made derivative of class in theme's 'template.php' pagination custom theme , works great, i'm missing when comes getting work through returned single posts.

should give , use custom page template displays 1 full article per page know pagination works charm? that, want right. that's goal.

here's have far in single.php:

get_header(); ?>      <div id="primary">         <div id="content" role="main">        <?php $paged = (get_query_var('paged')) ? get_query_var('paged') : 1; ?>       <?php $wp_query = new wp_query('category_name=news_and_updates&showposts=1&paged=' . $paged);         while ($wp_query->have_posts()) : $wp_query->the_post();         ?>                  <?php get_template_part( 'content', 'single' ); ?>                  <?php comments_template( '', true ); ?>              <?php endwhile; ?>      <?php if (function_exists("pagination")) {       pagination($wp_query->max_num_pages);     } ?>          </div><!-- #content -->     </div><!-- #primary --> 

i found tutorial explains how tweak pagination replacing next/previous links 'paginate_links' object. can't seem work.

i know i'll need add class twentyeleven theme custom theme's 'functions.php', customize use numeric pagination , call either in single.php or single-content.php:

if ( ! function_exists( 'twentyeleven_content_nav' ) ) : /**  * display navigation next/previous pages when applicable  */ function twentyeleven_content_nav( $nav_id ) {     global $wp_query;      if ( $wp_query->max_num_pages > 1 ) : ?>         <nav id="<?php echo $nav_id; ?>">             <h3 class="assistive-text"><?php _e( 'post navigation', 'twentyeleven' ); ?></h3>            <div class="nav-previous"><?php next_posts_link( __( '<span class="meta-nav">&larr;</span> older posts', 'twentyeleven' ) ); ?></div>             <div class="nav-next"><?php previous_posts_link( __( 'newer posts <span class="meta-nav">&rarr;</span>', 'twentyeleven' ) ); ?></div>         </nav><!-- #nav-above -->     <?php endif; } endif; // twentyeleven_content_nav  /**  * return url first link found in post content.  *  * @since twenty eleven 1.0  * @return string|bool url or false when no link present.  */ function twentyeleven_url_grabber() {     if ( ! preg_match( '/<a\s[^>]*?href=[\'"](.+?)[\'"]/is', get_the_content(), $matches ) )         return false;      return esc_url_raw( $matches[1] ); } 

i'll keep editing post until figure out, unless who's done before answers.

i'm not sure if understand you're trying achieve, apologies if doesn't help.

by looks of want nest custom loop inside page. if want customise regular list of posts, should looking @ archive.php, not single.php. check out hierarchy details of different template types. in simplest form, archive pages display multiple posts (archive.php) , single pages displaying single post/page (single.php).

for custom loop inside page, avoid using $wp_query, used actual page you're looking @ , drive

for pagination, agree tutorial , use paginate_links. bit of css, should give effect want.

so in all, query should in simplest form.

$args=array(); // set $args whatever parameters query $args['category_name']='news_and_updates'; $args['showposts']=1; $args['paged']=(get_query_var('paged') ? get_query_var('paged') : 1); // current page, or show page 1. $search=new wp_query($args)    if($search->have_posts()) :       while($search->have_posts()) : $search->the_post();         the_title(); // whatever displaying each post.         the_excerpt();       endwhile;     /* pagination - assumes have 'pretty permalinks'. */     $ulpn=99999999; // should bigger number number of pages you'll ever produce.     $pagination=paginate_links(array(       'base'=>str_replace($ulpn,'%#%',esc_url(get_pagenum_link($ulpn))),       'format'=>'/page/%#%',       'current'=>max(1,get_query_var('paged')),       'total'=>$search->max_num_pages,       'prev_text'=>'<',       'next_text'=>'>',       'type'=>'array')); // there other parameters can use customise - check codex using link above.       if($pagination) { ?>         <div class="pagination"><?php foreach($pagination $page) { echo $page; } ?></div>       <?php }   else : ?>     <h2>sorry, no results found</h2>     <p>try searching, or using menu find you're looking for.</p> // handle no results whatever message   endif; 

Comments

Popular posts from this blog

c# - SVN Error : "svnadmin: E205000: Too many arguments" -

c# - Copy ObservableCollection to another ObservableCollection -

All overlapping substrings matching a java regex -