0

Is there a way to edit or add templates for navigation in categories ?

To be more specific, in the case of a news category that has multiple pages.

I would do something like this:

<footer class="footer">
<nav id="nav-below" class="navigation" role="navigation">
    <div class="nav-previous">
        <a href="#" rel="prev">
            <span class="meta-nav" aria-hidden="true">← Older</span>
        </a>
    </div>
    <div class="nav-next">
        <a href="#" rel="next">
            <span class="meta-nav" aria-hidden="true">Newer →</span> 
        </a>
    </div>
</nav>

Also, I do not want to see the page numbers. Only "Older" and "Newer".

Thanks for your help !


Update

Actually, I'm using modified Twenty Sixteen theme.

There is the code into category.php :

    <?php
        // Start the Loop.
        while ( have_posts() ) : the_post();

            /*
             * Include the Post-Format-specific template for the content.
             * If you want to override this in a child theme, then include a file
             * called content-___.php (where ___ is the Post Format name) and that will be used instead.
             */
            get_template_part( 'template-parts/content', get_post_format() );

        // End the loop.
        endwhile;

        // Previous/next page navigation.
        the_posts_pagination( array(
            'prev_text'          => __( '← older', 'twentysixteen' ),
            'next_text'          => __( 'newer →', 'twentysixteen' ),
            'before_page_number' => '<span class="meta-nav screen-reader-text">' . __( '', 'twentysixteen' ) . ' </span>',
        ) );

    // If no content, include the "No posts found" template.
    else :
        get_template_part( 'template-parts/content', 'none' );

    endif;
    ?>

When I try to replace this by something :

            // Previous/next page navigation.
        the_posts_pagination( array(
            'prev_text'          => __( '← older', 'twentysixteen' ),
            'next_text'          => __( 'newer →', 'twentysixteen' ),
            'before_page_number' => '<span class="meta-nav screen-reader-text">' . __( '', 'twentysixteen' ) . ' </span>',
        ) );

I'm getting a 500 error.

I would like to put your code in this, but really don't know how to do it.

<nav id="post-pagination" class="navigation" role="navigation">
<div class="nav-previous">
    <?php next_posts_link( '← Older', $the_query->max_num_pages ); ?>
</div>
<div class="nav-next">
    <?php previous_posts_link( 'Newer →' ); ?>
</div>

4
  • there is not time associated with categories - what would 'older' or 'newer' mean for a category, and where do you want to get this information from?
    – Michael
    Feb 17, 2016 at 2:00
  • To be more specific, in the case of a news category that has multiple pages. Newer and Older for articles in news category.
    – Meivyn
    Feb 17, 2016 at 2:02
  • that would be normal pagination - start by looking into codex.wordpress.org/Pagination
    – Michael
    Feb 17, 2016 at 2:04
  • Always getting a 500 error when I try to change the parameters of the loop. I'm not familiar with PHP.
    – Meivyn
    Feb 17, 2016 at 2:15

1 Answer 1

0

WordPress Pagination

You can use previous_posts_link and next_posts_link.

<nav id="post-pagination" class="navigation" role="navigation">
    <div class="nav-previous">
        <?php next_posts_link( '← Older', $the_query->max_num_pages ); ?>
    </div>
    <div class="nav-next">
        <?php previous_posts_link( 'Newer →' ); ?>
    </div>
</nav>

It's not important but Next and Previous have the opposite classes (.nav-previous on next_posts_link() & .nav-next on previous_posts_link()) because:

Because post queries are usually sorted in reverse chronological order, next_posts_link() usually points to older entries (toward the end of the set) and previous_posts_link() usually points to newer entries (toward the beginning of the set).


Update

Based on your code, something like this should work (although I'm not sure what's wrong with the original the_posts_pagination?):

    <?php
        // Start the Loop.
        while ( have_posts() ) : the_post();

            /*
             * Include the Post-Format-specific template for the content.
             * If you want to override this in a child theme, then include a file
             * called content-___.php (where ___ is the Post Format name) and that will be used instead.
             */
            get_template_part( 'template-parts/content', get_post_format() );

        // End the loop.
        endwhile;
    ?>

    <nav id="post-pagination" class="navigation" role="navigation">
        <div class="nav-previous">
            <?php next_posts_link( '← Older', $the_query->max_num_pages ); ?>
        </div>
        <div class="nav-next">
            <?php previous_posts_link( 'Newer →' ); ?>
        </div>
    </nav>

    <?php
    // If no content, include the "No posts found" template.
    else :
        get_template_part( 'template-parts/content', 'none' );

    endif;
    ?>
3
  • This one seems to work. Although I have an issue with my CSS, float property "delete" padding-bottom. Footer have a padding of 16px, and nav-previous have a float to left. I don't know why the padding-bottom 16px don't show.
    – Meivyn
    Feb 17, 2016 at 2:54
  • The precedent code was difficult to work with. My CSS is already applied on footer/nav. Also there was page numbers that I don't want.
    – Meivyn
    Feb 17, 2016 at 3:05
  • Anyway, I will find something to resolve this myself. A big thanks for your help, really appreciated !
    – Meivyn
    Feb 17, 2016 at 3:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.