WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Hacking numbered pagination (4 posts)

  1. Waqas
    Member
    Posted 8 months ago #

    I've come across a number pagination code for php. It is working 100%. But its not what I have

    <?php
    if($new_query->max_num_pages>1){?>
        <p class="pager">
        <?php
        for($i=1;$i<=$new_query->max_num_pages;$i++){?>
            <a href="<?php echo get_category_link($category_id).'page/'.$i;?>" <?php echo ($paged==$i)? 'class="active"':'';?>><?php echo $i;?></a>
            <?php
        }
        if($paged!=$new_query->max_num_pages){?>
            <a href="<?php echo get_category_link($category_id).'page/'.$i;?>">Siguiente</a>
        <?php } ?>
        </p>
    <?php } ?>

    The result of above code is:

    <p class="pager">
             <a href="page/1" class="active">1</a>
             <a href="page/2" >2</a>
             <a href="4">Siguiente</a>
    </p>

    But I want it to appread like this (using above code), I don't want 1st and last page links.

    <p class="pager">
             <a href="page/2" rel="2nd">2</a>
    </p>

    I don't want to use <?php next_posts_link(); ?> because I've multiple loops at a single.php and <?php next_posts_link(); ?> create pagination for the current post instead of loop.

    Any help will be appreciated.

    [bump moderated]

  2. martha_camellia
    Contributor Day Volunteer
    Posted 8 months ago #

    try this:

    <?php
    if($new_query->max_num_pages>1){?>
        <p class="pager">
        <?php
        for($i=2;$i<=$new_query->max_num_pages;$i++){?>
            <a href="<?php echo get_category_link($category_id).'page/'.$i;?>" <?php echo ($paged==$i)? 'class="active"':'';?>><?php echo $i;?></a>
            <?php
        }
        <?php } ?>
        </p>
    <?php } ?>
  3. Waqas
    Member
    Posted 8 months ago #

    Perfect, its working. Now the result is

    <a href="/page/2" >2</a>
    <a href="/page/3" >3</a>

    Althought I don't need <a href="/page/3" >3</a>, because I'm using infinite scroll. But still its working :)

    The above code has a syntex error, So here is the good one.

    <?php
    if($new_query->max_num_pages>1){?>
        <p class="pager">
        <?php for($i=2;$i<=$new_query->max_num_pages;$i++){?>
            <a href="<?php echo get_category_link($category_id).'/page/'.$i;?>"><?php echo $i;?></a>
            <?php }?>
        </p>
    <?php } ?>

    Thank you martha_camellia.

  4. Waqas
    Member
    Posted 8 months ago #

    Thank you once again. I'm makring this topic as resolved :)

Reply

You must log in to post.

About this Topic

Tags