• Resolved matek12345

    (@matek12345)


    Hi,

    I’m building a site, and i have caught a problem.

    I want to display posts in the loop and i want to show only one category posts,

    I have modified loop that only one category displays, it’s on template page,

    My problem is that i want to display on one page only 6 posts and have the option to navigate to older posts but in this category.

    I tried the posts_nav_link() but it doesn’t work, i read that’s because if i change default behaviour of the loop (like query_posts, get_post etc.) the next/prev doesn’t work.

    So my question is, is there some way, method, maybe plugin that i can display this navigation to older post.

    Thanks

Viewing 3 replies - 1 through 3 (of 3 total)
  • You need to amend the custom query to take account of multiple pages. Eg:

    <?php
    $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
    $args= array(
    	'posts_per_page' => 6,
    	'category_name' => 'News',
    	'paged' => $paged
    );
    query_posts($args);
    ?>
    Thread Starter matek12345

    (@matek12345)

    thanks for answer, and help, but it doesn’t work,

    maybe i will give the code that i have on my site, i tried many things, i tried this https://theodin.co.uk/blog/design/wordpress-pagination-wppagenavi-queryposts.html and one thing that now when i type in my url after whole url number eg: /2 i get the second page,

    i also tried this https://weblogtoolscollection.com/archives/2008/04/13/define-your-own-wordpress-loop-using-wp_query/ but this doesn’t work at all,

    I really don’t know where the problem is, and how to get it working, i really need this,

    i also tried with this plugin wp=pagenavi, but it only works on first site,

    that is my code after this first article adjust

    https://wordpress.pastebin.com/eLMrKjrX

    and this is before this first article adjustment, just the loop with category that i want to include

    https://wordpress.pastebin.com/gEzyP5V4

    Thanks a lot for help :]

    Thread Starter matek12345

    (@matek12345)

    Ok i used your code, man thank so much, i just have to adjust it a little, but it works, my code looks like this:

    <div>
    			<?php
    				//The Query
    				$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
    $args= array(
    	'posts_per_page' => 3,
    	'category_name' => 'czytelnia',
    	'paged' => $paged
    );
    query_posts($args);
    				 while ( have_posts() ) : the_post();
    			?>
    			<div class="box4" id="post-<?php the_ID(); ?>">
    
    				<div class="title4">
    					<?php $preview = get_post_meta($post->ID, 'preview', $single = true); ?>
    					<h2><a href="<?php the_permalink() ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a></h2>
    				</div>
    				<div class="sentry4">
    					<?php $preview = get_post_meta($post->ID, 'preview', $single = true); ?>
    					<img class="ethumb4" src="<?php bloginfo('stylesheet_directory'); ?>/timthumb.php?src=<?php echo $preview; ?>&h=100&w=290&zc=1" alt=""/> 
    
    					<?php the_excerpt(); ?>
    						<div class="clear"></div>
    				</div>
    							<div class="sinfo4">
    
    				<div class="rmore4"><a href="<?php the_permalink() ?>" title="Permanent Link to <?php the_title(); ?>"> Więcej... </a></div>
    
    			</div>
    			</div>
    			<?php endwhile; ?>
    
    <div style="text-align:center;">
    <?php posts_nav_link(); ?>
    </div>
    
    		</div>
    
    </div>

    thanks

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘older posts in changed loop, posts_nav_link’ is closed to new replies.