0

I've created a custom category.php for my client. The issue is, that if I click to next/prev pagination links, it shows the same posts. Any idea what can be wrong?

category.php

<?php
    /* Category template file */
    get_header();

    $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
    $the_query = new WP_Query( 'posts_per_page=2&paged=' . $paged ); 
?>

<div id="content">
    <img id="eu-logo" src="<?php bloginfo('template_url')?>/img/title.png" />

    <div class="article">

        <?php global $post;
        $args = array('category' => 11, 'posts_per_page' => 2, 'order_by' => 'date');
        $custom_posts = get_posts($args);
        foreach($custom_posts as $post) : setup_postdata($post);

        echo "<div class='post'><h2 class='article__title'><a href='";
        the_permalink();
        echo "'>";
        the_title();
        echo "</a></h2>";

        the_excerpt();
        echo "</div>";

        endforeach;

        echo "<div id='forum-link'>";
        echo "<a class='custom-nav' href='https://test.com'>Main Page</a><br />";
        echo "<a class='custom-nav' href='https://test.com/forum/'>Forum</a>";
        echo "</div>";

        ?>

    </div>

    <div><?php next_posts_link('Next Page &raquo;') ?></div>
    <div><?php previous_posts_link('&laquo; Previous Page') ?></div>

    <?php get_sidebar(); ?>
</div>

<?php get_footer(); ?>
  • You are missing 'paged' element in $args = array('category' => 11, 'posts_per_page' => 2, 'order_by' => 'date'); – Qaisar Feroz Mar 21 at 12:19
  • And how should I add it? – Gabriel Mar 21 at 12:21
  • Please see my answer – Qaisar Feroz Mar 21 at 12:26
1

This should be

$args = array('category' => 11, 'posts_per_page' => 2, 'order_by' => 'date');

like this

$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$args = array('category' => 11, 'posts_per_page' => 2, 'order_by' => 'date', 'paged' => $paged);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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