• Resolved joeyw

    (@joeyw)


    hello everyone,
    i’m tried to do a page of post per category and found this solution in the forum.

    code start:

    <?php if (have_posts()) : while (have_posts()) : the_post(); ?>
    		<div class="post-page" id="post-<?php the_ID(); ?>">
    		<h2><?php the_title(); ?></h2>
    			<div class="entry entry_page">
    				<?php the_content('<p class="serif">keep reading &raquo;</p>'); ?>
    
    				<?php wp_link_pages(array('before' => '<p><strong>pages:</strong> ', 'after' => '</p>', 'next_or_number' => 'number')); ?>
    
    				<?php edit_post_link('edit', '<br /><p>', '</p>'); ?>
    			</div>
    		</div>
    		<?php endwhile; endif; ?>

    and then it’s set the catID according to category name:

    <?php
    $catID = 0;
    if (is_page('new')) {
      $catID=4;
    } 
    
    if ($catID) {
       $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
       query_posts("cat=$catID&paged=$paged");
    } ?>

    and then it’s showing the posts:

    <?php if (have_posts()) : ?>
    
    		<?php while (have_posts()) : the_post(); ?>
    
    			<div class="post" id="post-<?php the_ID(); ?>">
                    <div class="post-top">
                        <div class="post-date">
                            <?php the_time('M') ?>
                        	<p><?php the_time('d') ?></p>
                        </div>
                        <div class="post-title">
                        	<h2><a href="<?php the_permalink() ?>" rel="bookmark" title="link<?php if ( function_exists('the_title_attribute')) the_title_attribute(); else the_title(); ?>"><?php the_title(); ?></a></h2>
                            <h3>
                            	publish by <?php the_author() ?> date <?php the_time('d-m-Y') ?>
                            </h3>
                            <?php if ( function_exists('the_tags')) the_tags('<h3 class="tags">tags: <span>', ', ', ' </span></h3>'); ?>
    
                        </div>
                    </div>
    
    and then it's have the pagination:
    		<?php endwhile; ?>
    
    		<div class="navigation">
    			<div class="alignleft"><?php next_posts_link('&laquo; previous post') ?></div>
    			<div class="alignright"><?php previous_posts_link('next post &raquo;') ?></div>
    		</div>

    and here are the problem,
    if i have lot’s of post and i limited posts to 4 per page
    a pagination appears to older posts, pressing it the page url will change to /page/2, so it’s increasing OK
    BUT
    the template show the same posts all over again it’s not replacing them with previous posts as it’s should be.
    please help me on this issue.
    here are a link to the complete code.

    https://pastebin.com/4Tv2hK0G
    thanks,
    joe.

Viewing 7 replies - 1 through 7 (of 7 total)
  • Here is a snippet that works here on a template page of all posts, you will need to add the category bit, and add rewind posts after.

    <?php
    	$wp_query= null;
    	$wp_query = new WP_Query();
    	$wp_query->query('showposts=13'.'&paged='.$paged);
    ?>

    Here is my page code a mix of twenty ten, twenty eleven and 1140 css, I use wp-pagenavi if you have a lot of posts you might want to look at this plugin.

    HTH

    David

    Thread Starter joeyw

    (@joeyw)

    hey david,
    you rock..!!!
    that’s solved the problem.
    simply added the snippet and waallaa pagination working,
    i don’t know what it do but it’s working.
    thanks a lot.

    i have tried your suggestion on pagenavi it’s cool,
    but can you help me on how to make it work in rtl website since the page numbers going one on top the other..?
    everything is backward as it’s was made to ltr websites.

    thanks,
    joe

    Hi Joe,
    Can you mark this one as resolved please.

    Answered you rtl question in the other post.

    Thanks

    David

    I think you forget to put robot text in there. Its must be exits with all robo text put the temlets once again and mention it with new one.

    Chek out the Error of :

    <div class=”navigation”>
    <div class=”alignleft”><?php next_posts_link(‘? previous post’) ?></div>
    <div class=”alignright”><?php previous_posts_link(‘next post ?’) ?></div>
    </div>

    And Clear it so You get the Solution.

    Design to Html

    Thread Starter joeyw

    (@joeyw)

    done.

    Thread Starter joeyw

    (@joeyw)

    hello david,
    sorry to bother you again,
    but the solution was great till i added more content page (page of posts template)

    at first i used your snippet:

    <?php
    	$wp_query= null;
    	$wp_query = new WP_Query();
    	$wp_query->query('showposts=13'.'&paged='.$paged);
    ?>

    and while i had 1 content page everything was great
    the problem started when i added more content page as i used for my page of posts template the solution suggested here in the forum
    in short the solution suggest is:

    <?php
    $catID = 0;
    if (is_page('contribute')) {
      $catID=6;
    } elseif (is_page('about')) {
      $catID=9;
    }
    
    if ($catID) {
       $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
       query_posts("cat=$catID&paged=$paged");
    } ?>

    seems that the snippet make it go crazy as it causing the page to show all posts no matter the category.

    thats how my code look like in short:

    <?php
    /*
    Template Name: PageOfPosts
    */
    get_header(); ?>
    
    	<div id="content" class="narrowcolumn">
    
    		<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
    		<div class="post-page" id="post-<?php the_ID(); ?>">
    		<h2><?php the_title(); ?></h2>
    			<div class="entry entry_page">
    				<?php the_content('<p class="serif">keep reading &raquo;</p>'); ?>
    
    				<?php wp_link_pages(array('before' => '<p><strong>pages:</strong> ', 'after' => '</p>', 'next_or_number' => 'number')); ?>
    
    				<?php edit_post_link('edit', '<br /><p>', '</p>'); ?>
    			</div>
    		</div>
    		<?php endwhile; endif; ?>
    
    <?php
    $temp = $wp_query;
    $wp_query= null;
    $wp_query = new WP_Query();
    $wp_query->query('showposts=4'.'&paged='.$paged);
    ?>       
    
    <?php
    $catID=0;
    if (is_page('joe'))
    {$catID=4;}
    elseif (is_page('adam'))
    {$catID=18;}
    
    if ($catID) {
       $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
       query_posts("cat=$catID&paged=$paged");
    } ?>
    
    <?php if (have_posts()) : ?>
    
    		<?php while (have_posts()) : the_post(); ?>

    and the complete page of posts template code is here

    can you please help me on this.
    thanks,
    joe.

    Thread Starter joeyw

    (@joeyw)

    please help, anyone..?

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘why Pagination not working..? please help’ is closed to new replies.