WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] older posts in changed loop, posts_nav_link (4 posts)

  1. matek12345
    Member
    Posted 4 years ago #

    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

  2. esmi
    Forum Moderator
    Posted 4 years ago #

    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);
    ?>
  3. matek12345
    Member
    Posted 4 years ago #

    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 http://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 http://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

    http://wordpress.pastebin.com/eLMrKjrX

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

    http://wordpress.pastebin.com/gEzyP5V4

    Thanks a lot for help :]

  4. matek12345
    Member
    Posted 4 years ago #

    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

Topic Closed

This topic has been closed to new replies.

About this Topic