• Resolved baberzaman

    (@baberzaman)


    I have just Created a New WordPress Theme. But i am failed in Pagination Step. I have created it but it is Showing Same Posts on All Paged Numbers.. Here are My Codes…

    Functions.php

    function pagination($pages = '', $range = 4)
    {
         $showitems = ($range * 2)+1;  
    
         global $paged;
         if(empty($paged)) $paged = 1;
    
         if($pages == '')
         {
             global $wp_query;
             $pages = $wp_query->max_num_pages;
             if(!$pages)
             {
                 $pages = 1;
             }
         }   
    
         if(1 != $pages)
         {
             echo "<div class=\"pagination\"><span>Page ".$paged." of ".$pages."</span>";
             if($paged > 2 && $paged > $range+1 && $showitems < $pages) echo "<a href='".get_pagenum_link(1)."'>&laquo; First</a>";
             if($paged > 1 && $showitems < $pages) echo "<a href='".get_pagenum_link($paged - 1)."'>&lsaquo; Previous</a>";
    
             for ($i=1; $i <= $pages; $i++)
             {
                 if (1 != $pages &&( !($i >= $paged+$range+1 || $i <= $paged-$range-1) || $pages <= $showitems ))
                 {
                     echo ($paged == $i)? "<span class=\"current\">".$i."</span>":"<a href='".get_pagenum_link($i)."' class=\"inactive\">".$i."</a>";
                 }
             }
    
             if ($paged < $pages && $showitems < $pages) echo "<a href=\"".get_pagenum_link($paged + 1)."\">Next &rsaquo;</a>";
             if ($paged < $pages-1 &&  $paged+$range-1 < $pages && $showitems < $pages) echo "<a href='".get_pagenum_link($pages)."'>Last &raquo;</a>";
             echo "</div>\n";
         }
    }

    Style.css

    ` .pagination {
    margin-left:25%;
    clear:both;
    padding:20px 0;
    position:relative;
    font-size:14px;
    font-weight:bold;
    line-height:18px;
    }

    .pagination span, .pagination a {
    display:block;
    float:left;
    margin: 2px 2px 2px 0;
    padding:6px 9px 5px 9px;
    text-decoration:none;
    width:auto;
    color:#fff;
    background:grey;
    }

    .pagination a:hover{
    color:#fff;
    background: #F9611E;
    }

    .pagination .current{
    padding:6px 9px 5px 9px;
    background: #F9611E;
    color:#fff;
    }`
    And in Index.php Page Under the Posts Codes.

    <?php query_posts('posts_per_page=7'); ?>
        <?php if (have_posts()) : ?>
        <?php while (have_posts()) : the_post(); ?>
    <br><br>
    <?php
    
    $content = get_the_content();
    $trimmed_content = wp_trim_words( $content, 50, '<a href="'. get_permalink() .'">... &nbsp;Read More</a>' );
    
    ?>
    
    <a href="<?php the_permalink(); ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>">
    <div class="title"><?php the_title(); ?></div></a>
    <div class="date">Posted on <?php the_time('l,  F j, Y'); ?> at <?php the_time('g:i a'); ?></div>
    
    <?php the_post_thumbnail(); ?>
    <div class="content"><?php echo $trimmed_content; ?></div>
    <br><br>
    <hr class="phr"/><!-- //Single Post  -->
    
    <?php endwhile; ?>
    
    <?php endif; ?>
    <hr class="phr">
        </div>
    <div align="center"><!--//Pagination-->
    <?php if (function_exists("pagination")) {
        pagination($additional_loop->max_num_pages);
    } ?></div>

    I have tried So much But i am watching same posts on Each Paged Posts.. To see my Page please visit this link.. https://jaylou.co/testwp/

    Thanks

Viewing 8 replies - 1 through 8 (of 8 total)
  • First Question: Why not use paginate_links() ?

    Thread Starter baberzaman

    (@baberzaman)

    CSloisel
    I am new to wordpress so i dont know how to use that.. So i used these codes.
    I want to get these work but i am failed even i tried to change many codes.
    And Moreover. i have used many type paginations. Even plugins. But all has same issue. Each paged Number shows same posts..

    You are using query_posts() at the top of the template file which you shouldn’t really be doing, you are adding an unnecessary extra query to the page load, but if you are going to keep it there you have to add the paged query var to the query args, otherwise it will always show the first page.

    Thread Starter baberzaman

    (@baberzaman)

    can you help me please that which thing i have to remove and which line have to add where..?? Please.. In detaill..

    Remove line 1:
    <?php query_posts('posts_per_page=7'); ?>
    and it should work.

    If you want to change the posts per page you should use the setting in the admin panel or add a filter to the main query.

    Thread Starter baberzaman

    (@baberzaman)

    ok. let me try this please..

    Thread Starter baberzaman

    (@baberzaman)

    WOW.. It is Working NOW. You are awesome..

    Thread Starter baberzaman

    (@baberzaman)

    thanks man..

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘WordPress Pagination Shows Same Page at all page numbers’ is closed to new replies.