定制类别.php分页显示相同的帖子

时间:2019-03-21 作者:Runtime Terror

我创建了一个自定义category.php 为了我的客户。问题是,如果我单击“下一页/上一页”链接,它会显示相同的帖子。知道有什么不对吗?

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(); ?>

1 个回复
最合适的回答,由SO网友:Qaisar Feroz 整理而成

这应该是

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

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

相关推荐

在Get_the_Posts_Pagination函数中编辑分页文本

我想在链接模板中编辑screen\\u reader\\u文本。php我可以在一个主题中这样做,这样它就不会在更新时被覆盖。看起来过滤器是最好的选择,但我找不到关于使用什么过滤器的文档。这是我想从链接模板更改的代码。php: if ( $GLOBALS[\'wp_query\']->max_num_pages > 1 ) { $args = wp_parse_args( $args, array( \'mid_size\' =&