Support » Themes and Templates » Numeric pagination of all posts in the single.php template

Numeric pagination of all posts in the single.php template

  • Hello and thank you in advance for any help. Firstly let me say that unfortunetly I cannot provide any URL because all code is on a local server. I am trying to achieve something that I believed would be easy enough however after googling for what seems like days not I have come up empty handed.

    I would like to mimic the numeric navigation of plugins like WP Page-navi on the Single.php template.

    Specifically I would like for users viewing a single post within the category “Projects” to be able to navigate to any of the other single project posts using a numeric list (displayed inline) … meaning all in one line … like this < 1 2 3 4 5 6 7 8 > … with each number linking to the permalink for that post … am I making sense?

    Everything I have found is either for paginating posts with more than one page or for paginating within page templates like index, archive and search page, but will not function with single post pages.

    Please, any light one could shed on my problem would be greatly appreciated. thank you.

Viewing 1 replies (of 1 total)
  • Ok so I havent figured out a complete solution yet – but I did find something that may help others out there so I thought I would share my results. I really just needed a list of 8 posts from the same Taxonomy to appear on the Single.php template page but rather than the titles being the clickable text I would have liked them to be numbered boxes – similar to WP-Pagenavi and others …

    What I was able to do was create a new loop further down in the template file and count each result and instead of displaying the_title(); I just echoed the count. Now I have a series of list items with linked numberes and although its no where near as robust as a plugin (no “first/last” links, no skipping large portions “10,20,30…”) I does work for my current needs and I hope the following code will help others. please post any additions and whatnot here to share as well.

    <?php $count = 1 ?>
    <?php $currentpost = get_the_ID(); ?>
    <?php $my_query = new WP_Query(array( 'your-taxonomy' => 'specific taxonomy', 'posts_per_page' => 8 ));
    while ($my_query->have_posts()) : $my_query->the_post(); ?>
    <li class="page-numbers"
    <?php if($currentpost == $post->ID)
    echo ' id="current" ';
    ?>><a href="<?php the_permalink(); ?>"><?php echo $count; ?></a></li>
    <?php $count = $count + 1 ?>
    <?php endwhile; ?>

    Ok I hope my Franken-code can help someone!
    Peace & Good Fortune!

Viewing 1 replies (of 1 total)
  • The topic ‘Numeric pagination of all posts in the single.php template’ is closed to new replies.
Skip to toolbar